Using .NET to Post a New BlogPost in Wordpress

Abstract: In this article we will see how we can use .Net and communicate with the most popular blogging tool Wordpress and post a new blog post. Before starting the development of our application, it is very important to learn about XML-RPC because we will be using XML-RPC to communicate with a Wordpress blog.

Using .NET to Post a New BlogPost In Wordpress

In this article we will see how we can use .Net and communicate with the most popular blogging tool Wordpress and post a new blog post. Before starting the development of our application, it is very important to learn about XML-RPC because we will be using XML-RPC to communicate with a Wordpress blog.

“It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet.

It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted processed and returned”

Wordpress is a web application written in PHP and mostly runs on Linux servers and our application will be a .Net application which will be running on a Windows desktop. Since both run on entirely different architecture and technology, we will be using XML messages to communicate between the blog and our desktop application.

To use XML-RPC in .Net, we will be using the XML-RPC.Net library. It can be downloaded from here.

“XML-RPC.NET is a library for implementing XML-RPC Services and clients in the .NET environment, supporting versions 1.0, 1.1, and 2.0 of the .NET runtime. The library has been in development since March 2001 and is used in many open-source and business application”

Wordpress uses XML-RPC interface and currently supports Blogger API, metaWeblog API, and the Movable Type API. We will be using MetaWeblog API and the function newPost for creating a new post in our wordpress blog.

The blogid, username, password and publish params are as in the Blogger API. newPost returns a string representation of the post id, again as defined by the Blogger API. The struct is where the juice is.

Let’s get started. Fire up Visual Studio.

Step 1: Add two Textboxes and a Button to the form. Following are the names and properties of controls.

In the above code, we made a call to the newPost function of the Wordpress blog via the url http://127.0.0.1/wpl/xmlrpc.php. If the new post is successful, we display the post id which is returned. Below are some of the screenshots of our application in action.

ShobanKumar, Client App Dev MVP, primarily works on ASP, ASP.NET, VB, VB.NET and PHP. You can also find him blogging at www.codegeeks.net and www.allaboutmoss.com. Follow him on twitter @shobankr

User Feedback

Comment posted by
Lobby J
on Tuesday, November 24, 2009 4:37 AM

Fun to read..although i would use Live writer in any case ;)

Comment posted by
Shoban Kumar
on Tuesday, November 24, 2009 1:55 PM

Yeah ;-) Live Write has much more options. This is just a basic code about how Live Write works.

Comment posted by
shailesh
on Friday, November 27, 2009 2:14 AM

Hi,
This is very nice blog.but would you please tell me how I can use MetaWeblog API with Asp.net ?
My Requirement is like , I will write down someline of code in Msword 2007 then i will do some formatting over there and when i click on publish button under the online service then all that line should come in this [XmlRpcMethod("metaWeblog.newPost")] method.
I have done many r and d on this but i could not get exact result when i made http handler for this and going to click on publish button from ms word then it showing me message that ' Word can not publish this...' and i m not executing a code which i write in my newpost method.
So please help me to solve out this problem....

Hey man, big thanks for posting this. I am writing a UI for a blog link network for my members site, www.affportal.com and this code is exactly what I was looking for. Thanks for making my job one heck of a lot easier.

Can you please suggest or provide a sample code to post blog when the xml-rpc is disable. Actually my requirement is to post blog on other sites when the xml-rpc is disable. Thanks in advance...

Comment posted by
Sarvesh
on Friday, September 9, 2011 6:36 AM

Hi,
I am getting "Method Not Allowed" error while posting the blog in wordpress.

Comment posted by
adam
on Wednesday, November 16, 2011 7:49 AM

hi thank you for your post. the code works perfectly but do you know how to create custom fields with c#?

Comment posted by
Bibhu Dutta
on Thursday, November 17, 2011 3:48 AM

Hi, I am getting "Method not allowed" exception.

Comment posted by
John
on Tuesday, January 24, 2012 4:51 PM

I get a fault Exception [500] Content,Title and Excerpt are empty error...any suggestions?

Comment posted by
John
on Tuesday, March 13, 2012 12:19 AM

Anything?

Comment posted by
tori
on Saturday, May 26, 2012 12:43 PM

this code does not work.

and it posts only to the default uncategorized category. i tried to change post id but it still posts to the same default category.

you even miss :

Public Structure category
Public categoryId As Object
Public parentId As Object
Public description As Object
Public categoryName As Object
Public htmlUrl As Object
Public rssUrl As Object
End Structure

Comment posted by
Akash
on Monday, June 11, 2012 3:08 AM

Hey there,
Thanx for the code explanation,
but how would i get my "blog id".??

how can i edit post in word press?
can any one share source code for
metaWeblog.editPost (postid, username, password, struct, publish) returns true

Comment posted by
Selin
on Saturday, November 3, 2012 12:48 AM

Thank you for your article. It was great finding this cıde. I have been trying for a month to send an article from c# to wordpress with webbrowser. Then I met your article and i learnt about xml-rpc library.

Comment posted by
Jerz
on Tuesday, November 13, 2012 10:32 PM

Does this work in Visual Basic Express 2010?

Comment posted by
asway
on Wednesday, December 19, 2012 6:12 PM

how to attach image with .NET VB?

Comment posted by
David
on Friday, January 4, 2013 1:54 PM

This is not working for me at all, I even copied the instructions step by step several times and has a whole lot of errors.

Comment posted by
michael clood
on Sunday, January 6, 2013 2:37 PM

how to set another category for new post?

Comment posted by
dusijun
on Thursday, March 28, 2013 4:50 AM

Thanks, test your code. It works.

Comment posted by
Tonino
on Thursday, April 11, 2013 4:09 PM

Thanks.
VB
I modified Structure
Public Structure blogInfo
Public title As String
Public description As String
Public categories() As String
End Structure