BlogLib uses XML-RPC.NET, so you'll need to get that too.
Code Samples
C# Code Sample 1
In this sample we simply specify the URL to our XML-RPC server, create a
MovableTypeInterface object, and create a new post. The only value that might
not be readily available to you is your blog's 'blogid'. To find this, you'll
have to use the GetUsersBlogs() function, which returns a list of blogs that
your username and password give you credentials for. If you're really feeling
adventurous, the meat of this can be compressed down to one line.
using System;
using BlogLib;
namespace BlogLibClient
{
class Samp1
{
[STAThread]
static void Main(string[] args)
{
MovableTypeInterface mt = new MovableTypeInterface("http://mydomain.com/mt/mt-xmlrpc.cgi");
mt.NewPost(
"1", // blogid
"myusername",
"mypassword",
"This is the title value",
"This is a test of my BlogLib client code.",
DateTime.Now,
true // publish post
);
}
}
}
C# Code Sample 2
This sample shows how to set a post's categories and publish a post in a
separate call. The category "id" values may not be known to you, so you'll have
to call the GetBlogCategories() function and figure out which category id you
want to use.
using System;
using BlogLib;
namespace BlogLibClient
{
class Samp2
{
[STAThread]
static void Main(string[] args)
{
MovableTypeInterface mt = new MovableTypeInterface("http://mydomain.com/mt/mt-xmlrpc.cgi");
// Create a new post
string myPost = mt.NewPost(
"1", // blogid
"myusername",
"mypassword",
"This is the title value",
"This is a test of my BlogLib client code.",
DateTime.Now,
false
);
// Create post category array
MovableTypeInterface.SetPostCategory[] myCategories = new MovableTypeInterface.SetPostCategory[] {
mt.BuildSetPostCategory("1", true),
mt.BuildSetPostCategory("7", false)
};
// Set post categories
mt.SetPostCategories(myPost, "myusername", "mypassword", myCategories);
// Publish post
mt.PublishPost(myPost, "myusername", "mypassword");
}
}
}
C# Code Sample 3
This code demonstrates how to retrieve entries from a Movable Type blog.
using System;
using BlogLib;
namespace BlogLibClient
{
class Samp3
{
[STAThread]
static void Main(string[] args)
{
MovableTypeInterface mt = new MovableTypeInterface("http://mydomain.com/mt/mt-xmlrpc.cgi");
// Retrieve posts from blog
MovableTypeInterface.PostInfo[] posts = mt.GetRecentPosts("1", "myusername", "mypassword", 10);
foreach(MovableTypeInterface.PostInfo pi in posts)
{
Console.WriteLine( "[" + pi.title + ", " + pi.dateCreated + "]");
Console.WriteLine( pi.description + "\n");
}
}
}
}
C# Code Sample 4
This is an example of a simple command line client -- not exactly the best environment for creating blog posts but you get the idea.
using System;
using BlogLib;
namespace BlogLibClient
{
class Samp4
{
[STAThread]
static void Main(string[] args)
{
Console.Write("XML-RPC URL: ");
string URL = Console.ReadLine();
Console.Write("blogid: ");
string blogid = Console.ReadLine();
Console.Write("username: ");
string username = Console.ReadLine();
Console.Write("password: ");
string password = Console.ReadLine();
Console.Write("Post Title: ");
string title = Console.ReadLine();
Console.Write("Post Body: ");
string body = Console.ReadLine();
Console.Write("Number of Previous Posts to Retrieve: ");
int numToGet = Convert.ToInt32(Console.ReadLine());
try
{
// Set up interface
MovableTypeInterface mt = new MovableTypeInterface(URL);
Console.WriteLine("Working...\n");
// Create a new post
string myPost = mt.NewPost(blogid, username, password, title, body, DateTime.Now, false);
// Retrieve posts from blog
MovableTypeInterface.PostInfo[] posts = mt.GetRecentPosts(blogid, username, password, numToGet);
// Print out posts
foreach(MovableTypeInterface.PostInfo pi in posts)
{
Console.WriteLine( "[" + pi.title + ", " + pi.dateCreated + "]");
Console.WriteLine( pi.description + "\n");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
Other Stuff
Contact me
Some other projects of mine.