Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Created April 23, 2011 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmemcpy/938655 to your computer and use it in GitHub Desktop.
Save hmemcpy/938655 to your computer and use it in GitHub Desktop.
Updating the blog contents from within PublishNotificationHook
// based on an old blog post in Japanese: http://blog.sharplab.net/computer/cprograming/windowslivewriter/433/
// The field was moved to a base type in the latest version of Live Writer
using System.Reflection;
using WindowsLive.Writer.Api;
using WindowsLive.Writer.Extensibility.BlogClient;
using WindowsLive.Writer.PostEditor;
namespace WindowsLiveWriterPlugin.Extensions
{
public static class PublishingContextExtensions
{
public static void ReplaceText(this IPublishingContext publishingContext, string newText)
{
FieldInfo fieldInfo = publishingContext.GetType().BaseType.GetField("_editingContext", BindingFlags.NonPublic | BindingFlags.Instance);
BlogPostEditingManager manager = (BlogPostEditingManager)fieldInfo.GetValue(publishingContext);
BlogPost blogPost = (BlogPost)publishingContext.PostInfo;
blogPost.Contents = newText;
manager.EditPost(new BlogPostEditingContext(manager.BlogId, blogPost));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment