Library tutorials & articles
How to access Outlook and post to a blog using C#
- Introduction
- Posting to your blog
- Accessing the web service
Posting to your blog
Obviously everyone is using different software to manage their blog. I can't give an example of every single method, however the simplest from a programmers perspective is if you can access the database of your blog via a webservice, and this is what we'll deal with here. For a full tutorial on building web services in .NET, check out this article.
Choose to add a new webservice to your site, or create an entirely independant project and call it something suitable - ours will be blog because it's an example. Firstly, you will need to add a few more items to your using list, so you can do XML serialisation of structures and objects. I will assume your database is MS SQL Server too, so ensure the following are listed in addition to the defaults for a webservice:
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Common;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml.Serialization;
You want to be as object oriented as possible when building your webservice, so you should define a NewsItem structure to pass back and forth, you can adjust this to include whatever you need to store in an article:
public struct NewsItem
{
public int id;
public string topic;
public string subject;
public string postedby;
public DateTime postedate;
public string content;
}
This will allow you to reference rows in your database as objects, a simple organisational benefit that crosses over and permits easy use of methods of the webservice without passing a lot of parameters. It also allows you to add groups of entries to an ArrayList, which is a big benefit (although there is a problem converting from an object transferred by a webservice and an ArrayList, if you ever do this you will need to iterate through the object and add the entries back to an ArrayList - .NET does not support converting from an object[] to an ArrayList).
You can then build your method for adding the article to the database. I have used the database on my blog as an example, you will obviously need to change the insert statement and connection string to fit your situation. There is also no exception handling, ideally you should enclose the opening of the connection and the executing of the query in try...catch blocks.
Note that the XmlInclude for the NewsItem struct is listed, this allows the webservice to accept a newsitem given as a parameter - otherwise if would not know to serialise the structure.
[WebMethod]
[XmlInclude(typeof(NewsItem))]
public void AddArticle(NewsItem newarticle)
{
SqlConnection sqlcn = new SqlConnection("Data Source=(local);" +
"Initial Catalog=NullifyDB;" +
"Integrated Security=SSPI");
sqlcn.Open();
SqlCommand sqlcmd = new SqlCommand("INSERT INTO newsarticle (subject, topic, content, uid) VALUES (@subject, @topic, @content, @postedby);", sqlcn);
sqlcmd.Parameters.Add("@subject", newarticle.subject);
sqlcmd.Parameters.Add("@topic", newarticle.topic);
sqlcmd.Parameters.Add("@content", newarticle.content);
sqlcmd.Parameters.Add("@postedby", 253);
sqlcmd.ExecuteNonQuery();
sqlcn.Close();
}
You should then provide additional methods for anything else you would want to do, such as listing articles, deleting articles, and editing. For Outlook integration you really only need this method.
Related articles
Related discussion
-
Help please for student
by mandy130 (0 replies)
-
Loop help needed
by BKRoberts (5 replies)
-
Problem after strong naming an assembly
by rinkurathor1 (0 replies)
-
Regarding User control creation in C# .Net(Windows Application)
by porchelvi (0 replies)
-
Access Database Refreshing
by ranjithmadawala (0 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
I am working for fetching contacts from outlook express. I have explored a lot , But I couldn't .
How can I get access microsoft outlook express's conatacts?
Is this possible?
Hii Friends,
This is kumar, I facing the following problm. If Any body knows the solution please pass the solution to my E-Mail Id.
Query: How To Dynamically Pass The .aspx Page Values Into an .Html Page In ASP.NET + C#. Here I am Passing more than one value. I dont want to write hard code.
Query: I am writing the code for getting the data from database. In this data i have images. Then i have to pass these images to web page. Its like a banner Engine. But, Here i dont wont to take a "adrotator". I had taken a Html Iframe control. Then I have to pass the image name throuth src. Then i had verified and got the required images through database comparisons. When i run the application i have to display the web like "http://wepage1.aspx/sample.html". In this sample.html page is the dynamic page. When u run the web page ".aspx" that time i need to display/ pass these wepage image values to .html(sample.html) page.
How this is possible? If anybody knows the solution please pass the solution to my ID
Thnx and Regards
Naresh Kumar
ravuri_naresh@yahoo.co.in
hello,
I want somre help from u.we are using check boxes in datagrid for activating and deactivating.how to put that
check boxes in datagrid and reflect changes in database
thank you,
MohanVarma.
This thread is for discussions of How to access Outlook and post to a blog using C#.