Click here to Skip to main content
15,868,014 members
Articles / Web Development / ASP.NET
Tip/Trick

Submit a New Blog Post in WordPress using ASP.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
1 Jan 2013CPOL1 min read 40K   17   12
How to submit a new blog post in WordPress using ASP.NET

Introduction

WordPress is a free and open source blogging tool and content management system based on PHP and MySQL. It is used widely around the world and is currently the most famous blogging systems in use over the internet.

Since WordPress is written in PHP and our application is going to be an ASP.NET application and the two are entirely different technologies and architectures, we will be using XML messages (platform independent) for communications.

WordPress provides an XML-RPC based webservice for communication with different technologies and an application which can be found on the root directory with the name xmlrpc.php.

ASP.NET requires a library XML-RPC.NET to implement and communicate XML-RPC based webservices.

Prerequisites

You are required to have the following installed before you can jump into the code, they are:

  1. A WordPress blog, you can download it from here.
  2. An XML-RPC .NET library, which can be downloaded from here.

I will be assuming that you have your blog ready and have the admin privileges to access and update any setting you may require to change.

Using the Code

Create a new website and add two textboxes and a button onto the form with the following properties:

  • Textbox1: Name -> txtTitle
  • Textbox2: Name -> txtDescription

Now extract the downloaded zip file containing the XML-RPC .NET library and add a reference to CookComputing.XmlRpcV2.dll in the bin folder.

Now add the following code:

C#
public struct blogInfo
{
    public string title;
    public string description;
}

public interface IgetCatList
{
    [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
    string NewPage(int blogId, string strUserName, 
    	string strPassword, blogInfo content, int publish);
}   

We are done with creating a struct for blog info and an interface for the WordPress API. Now add the following code to the button click event:

C#
blogInfo newBlogPost = default(blogInfo);
newBlogPost.title = txtTitle.Text;
newBlogPost.description = txtPost.Text;

IgetCatList categories = (IgetCatList)XmlRpcProxyGen.Create(typeof(IgetCatList));
XmlRpcClientProtocol clientProtocol = (XmlRpcClientProtocol)categories;

clientProtocol.Url = "http://localhost:8080/wordpress/xmlrpc.php"; //your blog address comes here
string result = null;

result = "";

try
{
    result = categories.NewPage(1, 
                        "admin", //your blog admin user id
                        "Admin", //your blog admin password
                        newBlogPost, 
                        1);
    
    txtPost.Text = "";
    txtTitle.Text = "";
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}  

Image 1

Image 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWordPress and its uniqueness Pin
Member 1222491318-Jan-16 0:37
Member 1222491318-Jan-16 0:37 
QuestionHere i cant get id from return result Pin
Dhinesh kumar.V6-Oct-15 18:54
Dhinesh kumar.V6-Oct-15 18:54 
QuestionPost with categories Pin
Ageng Dwi Prastyawan26-Feb-15 20:06
Ageng Dwi Prastyawan26-Feb-15 20:06 
QuestionResponse from server does not contain valid xml. Pin
InaamurRehman7-Jan-14 2:50
InaamurRehman7-Jan-14 2:50 
AnswerRe: Response from server does not contain valid xml. Pin
Hasham Ahmad13-Jan-14 1:17
Hasham Ahmad13-Jan-14 1:17 
GeneralMy vote of 5 Pin
Member 813735416-Jan-13 9:38
Member 813735416-Jan-13 9:38 
GeneralMy vote of 5 Pin
Nouman Zakir8-Jan-13 7:24
Nouman Zakir8-Jan-13 7:24 
GeneralMy vote of 5 Pin
Shumaila Anjum2-Jan-13 23:31
Shumaila Anjum2-Jan-13 23:31 
AnswerGuud one (Y) Pin
Shumaila Anjum1-Jan-13 20:06
Shumaila Anjum1-Jan-13 20:06 
QuestionNice and Helpful (Y) Pin
Shumaila Anjum1-Jan-13 19:28
Shumaila Anjum1-Jan-13 19:28 
GeneralMy vote of 5 Pin
Sheikh Muhammad Haris1-Jan-13 3:36
Sheikh Muhammad Haris1-Jan-13 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.