首先请看这两篇Blog

http://weblogs.asp.net/lkempe/archive/2006/08/27/C_2300_-implementation-of-newMediaObject-for-the-MetaWeblog-API.aspx

http://www.cnblogs.com/Luna/archive/2006/09/08/498799.html

基本原理已经讲明白了,因为例子中代码没有和DotText的相册整合,所以需要自己动手做一点改动,使LiveWriter的照片能直接上传到DotText的相册中,方便管理,也没有多少技术含量,直接贴上代码,省得大家做重复劳动。

MetaWeblogAPI.cs 中增加:

----------------------------------------------------

public struct MediaObjectUrl
{
public string url;
}

public struct MediaObject
{
public string name;
public string type;
public byte[] bits;
}

?

public interface IMetaWeblog
{

//新增接口

[XmlRpcMethod("metaWeblog.newMediaObject",
Description="Add a media object to a post using the "
+ "metaWeblog API. Returns media url as a string.")]
MediaObjectUrl newMediaObject(
string blogid,
string username,
string password,
MediaObject mediaObject);

}

----------------------------------------------------

MetaWeblog.cs中新增

----------------------------------------------------

///


/// Post a media object.
///

/// The blogid.
/// The username.
/// The password.
/// The media object.
/// MediaObjectUrl defining the url of the media
public MediaObjectUrl newMediaObject(string blogid, string username,
string password, MediaObject mediaObject)
{

BlogConfig config = Config.CurrentBlog();
if(ValidateUser(username,password,config.AllowServiceAccess))
{
mediaObject.name = mediaObject.name.Replace("/", "_");
int categoryId = GetMetaWeblogImageCategoryId();

Dottext.Framework.Components.Image image = new Dottext.Framework.Components.Image();
image.CategoryID = categoryId;
image.Title = mediaObject.name;
image.IsActive = true;
image.File = mediaObject.name;
image.LocalFilePath = string.Format("{0}\\{1}\\",config.ImageDirectory,categoryId);
int imageID = Images.InsertImage(image, mediaObject.bits);

string imagePath = config.ImagePath;
MediaObjectUrl mediaObjectUrl = new MediaObjectUrl();
mediaObjectUrl.url = String.Format("{0}{1}", string.Format("{0}{1}/", imagePath,categoryId),
image.OriginalFile);
return mediaObjectUrl;
}
throw new XmlRpcFaultException(0,"User does not exist");
}

private int GetMetaWeblogImageCategoryId()
{
string name = "Meta Weblog Images"
LinkCategoryCollection categories = Links.GetCategories(CategoryType.ImageCollection, false);
foreach(LinkCategory lc in categories)
{
if (lc.Title == name)
{
return lc.CategoryID;
}
}

LinkCategory category = new LinkCategory();
category.CategoryType = CategoryType.ImageCollection;
category.Title = name;
category.IsActive = true;
category.Description = "MetaWeblogAIP专用,请勿删除和修改此分类!"

return Links.CreateLinkCategory(category);
}