Created
April 23, 2011 14:38
-
-
Save hmemcpy/938655 to your computer and use it in GitHub Desktop.
Updating the blog contents from within PublishNotificationHook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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