Windows Live Writer Automation

时间:2011-12-13 14:37:43

标签: c# windows-live-writer

我希望能够从我的(C#)应用程序打开Windows Live Writer,并填写博客文章的开头。

这应该很简单。 Windows Live Writer定义了一个Application API,它公开了一个名为WindowsLiveWriterApplicationLib的COM接口。根据{{​​3}}之类的博客帖子,在你添加对typelib的新引用后(通常位于此处:C:\ Program Files(x86)\ Windows Live \ Writer \ WindowsLiveWriter.Application.tlb),你应​​该是能够编写这样的代码:

static void Main(string[] args)
{

    var wlw = new WindowsLiveWriterApplicationLib.WindowsLiveWriterApplicationClass();
    wlw.BlogThisHtml("test","test");

}

......除了它不起作用。没有事件编译。相反,我得到这样的错误:

Error   1   The type 'WindowsLiveWriterApplicationLib.WindowsLiveWriterApplicationClass' has no constructors defined    

Error   2   Interop type 'WindowsLiveWriterApplicationLib.WindowsLiveWriterApplicationClass' cannot be embedded. Use the applicable interface instead.  

Error   3   'WindowsLiveWriterApplicationLib.WindowsLiveWriterApplicationClass' does not contain a definition for 'BlogThisHtml' and no extension method 'BlogThisHtml' accepting a first argument of type 'WindowsLiveWriterApplicationLib.WindowsLiveWriterApplicationClass' could be found (are you missing a using directive or an assembly reference?) 

它声称该类不能嵌入,没有构造函数,并且不包含我调用的方法。 (当它在对象资源管理器中清楚地显示时。)

我在这里错过了什么明显的事情?

1 个答案:

答案 0 :(得分:3)

管理以使其正常运行。

我不得不使用RegSvr32.exe注册WindowsLiveWriter.Application.dll。之后就开始工作了。

这是工作代码:

static void Main(string[] args)
{

    WindowsLiveWriterApplication wlw = new WindowsLiveWriterApplication();
    ((IWindowsLiveWriterApplication2)wlw).BlogThisHtml("test", "testhtml");

}