How to Use JoeBlog WordPress Wrapper – Tutorial with Examples

joeblogs wordpress wrapper how to fix

In this tutorial I will show you how to use JoeBlogs WordPress Wrapper based on XML-RPC to auto post to WordPress from an C# Application and for beginners how to post to WordPress from c# .net. I will show you also how to add images with JoeBlogs and how to auto complete custom fields directly from your .Net (C# Examples) Application.

First of all you have to download latest version of wrapper from GitHub or Here the version which I have used on my example.

Now create a new C# application and let’s start.

1.Adding Dependencies Libs

UnRar downloaded files to C:\Libs directory for example.

Right-Click on Project Name from Solution Explorer >> Add >> Reference...

joeblogs dependencies

Then Browse >> Click and Browse Button and Select "CookComputing.XmlRpcV2.dll" "JoeBlogs.dll" >> Add

joeblogs xml rpc wrapper

Now the final step is to add this to your code:

using JoeBlogs;

And now we are ready to start using JoeBlogs XML-RPC Wrapper.

2.How to use JoeBlogs:

This simple example code will help you to understand how to use JoeBlogs WordPress Wrapper:

string link = "http://website.com";
string username = "yourUserName";
string password = "password";

var wp = new WordPressWrapper(link + "/xmlrpc.php" , username, password);
var post = new Post();

post.DateCreated = DateTime.Today.AddHours(0);
post.Title = "Post Totle";
post.Body = "HowToFix.pro Content Here - Test post";
post.Tags = tags.Split(','); // string tags = "tags1,tag2";

wp.NewPost(post, true);

Adding an image with JoeBlogs WordPress Wrapper:

byte[] imageData = System.IO.File.ReadAllBytes("pathToImage");
var image = wp.NewMediaObject(new MediaObject { Bits = imageData, Name = "nameAfterUploading" });
string linkToImage = image.URL; //use this in your post

Adding custom fields on JoeBlogs WordPress Wrapper:

var cfs = new CustomField[]
{
    new CustomField()
    {
        Key = "_aioseop_title",
        Value = "AIO Title"
    },
    new CustomField()
    {
        Key = "_aioseop_description",
        Value = "AIO Description"
    },
    new CustomField()
    {
        Key = "_aioseop_keywords",
        Value = "AIO Tags"
    }
};

//Use it in this way
post.CustomFields = cfs;

OK, but now where I can take from the Key value? From Database >> wp_postmeta Table.

If you want to complete All In One SEO Fields first you have to make sure that you have Unprotect Post Meta Fields because you are not able to modify protected meta with XML-RPC WordPress API.

all in one seo custom fields xml rpc joeblogs

3.Whole JoeBlogs XML-RPC WordPress Wrapper Example Function:


private void postToWordpress(string title, string postContent, string tags, string aioTitle, string aioContent, string aioTags)
{
    string link = this.maskedTextBox1.Text;
    string username = this.maskedTextBox2.Text;
    string password = this.maskedTextBox3.Text;
    // webBrowser1.Navigate(url); -- IE -- pass this shit

    var wp = new WordPressWrapper(link + "/xmlrpc.php"/*fuck this shit*/, username, password);

    /* if you want to upload an image
    byte[] imageData = System.IO.File.ReadAllBytes("image.png");
    var image = wp.NewMediaObject(new MediaObject { Bits = imageData, Name = "image" });
    str = str.Replace("[SCREENSHOT1]", image.URL);
    */
    var post = new Post();
    post.DateCreated = DateTime.Today.AddHours(0);
    post.Title = title;
    post.Body = postContent;
    post.Tags = tags.Split(',');

    if (checkBox1.Checked == true) //if AIO is enabled
    {
        ////Let distraction come --- custom fields///
        var cfs = new CustomField[]
        {
            new CustomField()
            {
                Key = "_aioseop_title",
                Value = aioTitle
            },
            new CustomField()
            {
                Key = "_aioseop_description",
                Value = aioContent
            },
            new CustomField()
            {
                Key = "_aioseop_keywords",
                Value = aioTags
            }
        };

        post.CustomFields = cfs;

        ////after ..zzZZzz. hours..zzZZzzZzzzzZZZ..5:00 PM distraction enddddddddd..zZZzzZz(0_o)zZzzzZZZz    */
    }
    wp.NewPost(post, false);

    // save post link to a text file 🙂
    if(System.IO.File.Exists("links.txt"))
    {
        string buff = System.IO.File.ReadAllText("links.txt");
        buff = buff + System.Environment.NewLine + wp.GetPost(post.PostID).ToString();
        System.IO.File.WriteAllText("links.txt", buff);
        }

    MessageBox.Show("Posted :)");
}

4.Full Application Example:

I have made a little Application which is using JoeBlogs WordPress Wrapper to post to a  WordPress Blog:

joeblogs wordpress wrapper c application

Download whole project here:  JoeBlogsWordpressWrapperTests.rar

5.Conclusions

You know now how to use JoeBlogs WordPress Wrapper to Post to WordPress, Add Images to WordPress and Complete custom fields from an C# Application and generally .Net Application.

Please comment if you have something to ask.PS: Special thanks to Shiva

Related posts:

17 Comments on "How to Use JoeBlog WordPress Wrapper – Tutorial with Examples"

  1. Wojtek says:

    Very good introduction to JoeBlogs. I found there is a lack of ; in the first line of the example in section 2, but it’s not a problem for tme programmer. Thank you!

  2. skyfrit says:

    Very good tutorial.I have a question,how to add featured image.Thank you.

  3. Alex Brown says:

    Nice write up on JoeBlogs…. thanks!
    I’ve neglected this wrapper recently, I hope to tidy it up and add more features to it soon!

  4. Chris says:

    Hi, nice tutorial, and thanks to the author of the library Alex Brown 🙂 This tutorial is for posting things under ‘Posts’. Can anybody point me to the right direction of posting under ‘Gallery’? I’ve been searching for days to no avail. Can the library be tweaked to post under ‘Gallery’ instead of ‘Posts’? Thank you very much.

  5. Hello,
    I want to use joeblogs to post custom posttypes but it returns 401 error “Server returned a fault exception: [401] Geçersiz yazı tipi”

  6. morteza says:

    how can selected multi category by this way please help me.

  7. A.D says:

    Great article, this wrapper is great, however there is not much information around, for folks like me coming from a .net background its truly a life saver.
    Is there anyone around developing this wrapper any further, any other documentation sources?
    I have been looking for a way to send the author name, short bio and image using the wrapper without using the extra fields, is this possible?

  8. nani says:

    hello sir, good wrapper. its working.
    but unable to publish, it automatically crates post as scheduled .
    and after uploading image, don’t show image.
    please check this link
    https://drive.google.com/file/d/0ByDtRQyGAlYXRmhqaURDLS03MzQ/view?usp=sharing
    thank you.

    • admin says:

      Yo have to set date and time to avoid your post to be scheduled.
      For image uploading you use:
      ==================================================================

      byte[] imageData = System.IO.File.ReadAllBytes("image.png");
       var image = wp.NewMediaObject(new MediaObject { Bits = imageData, Name = "image" });

      ==================================================================
      And then add url to image in your post with:

      image.URL.ToString();
  9. Tayfun says:

    How to set image thumbnail?

  10. Raul_FLC says:

    How do I check if the web already contains the title?
    for example, I’ll post a post, you already have a title with that he did not put.

    Sorry for my inglish, I’m not speak very much…

  11. Jonn says:

    Getting this error when publishing:
    An unhandled exception of type ‘CookComputing.XmlRpc.XmlRpcServerException’ occurred in CookComputing.XmlRpcV2.dll

    Line: wp.NewPost(post, true);

  12. wahab says:

    hi

    How can i add post thumbnail using joeblogs

    sample code needed

    thanks

Got something to say? Go for it!