Any way to get post Title, URL, etc. from within a plugin?

I am writing a plugin for Digg This. I am pretty much finished with it. However, I would like to be able to automatically insert the URL of the post, or automatically specify the title of the post. Is there a way to get this information from a plugin?
[252 byte] By [LeoVildosola] at [2008-2-22]
# 1
I'll assume you mean the final permalink of the blog entry. I had the same thought, but unfortunately Writer doesn't actually get that information until after the post has been published.
Sc?tt at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 2

Ye, that's exactly what I mean. I assumed we were not able to get such information since the API does not have anything of the sort, but I thought I'd ask anyway.

How about the Post Title? Does anyone know the id or name WLW uses to represent the div that holds the Post Title? If I know that I can at least get the title.

LeoVildosola at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 3
Now that one I don't know, although I'm pretty sure it can't be grabbed. The only part of the API that I know does deal with the post title is when doing a "Blog This" call to Live Writer and you actually set the title yourself. Other than that, I don't think it can be done.
Sc?tt at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 4

I already have code that allows me to get the HTML from the WLW editor. Therefore, I am able to easily extract the post tile by using the following regular expression pattern.

@"<div[\s]+class=postTitle.*?>(?<postTitle>.*?)</div>"

I then do a match against the post's HTML and voila!

LeoVildosola at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 5
Leo Vildosola wrote:

I already have code that allows me to get the HTML from the WLW editor. Therefore, I am able to easily extract the post tile by using the following regular expression pattern.

@"<div[\s]+class=postTitle.*?>(?<postTitle>.*?)</div>"

I then do a match against the post's HTML and voila!

That is an interesting answer, for when I posed that to the WLW team the answer was that HTML was not accessible through a plugin...care to share?

OmegaMan at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 6
It is true that the HTML is not accessible through the SDK and therefore through a plugin. However, I managed to compile some code to get access to the HTML and replace it. The trick takes advantage of the fact that WLW uses a browser component for its editor and that can be retrieved using the Win32 APIs. From there you can get the full contents or the selected contents to manipulate.

I have isolated the code in an assembly. If you use my Code Snippet plugin for Windows Live Writer or my Digg This plugin for Windows Live Writer, you will get an assembly called WLWPluginBase.dll in your plugin folder. All my plugins use that same assembly. This is where all that code is isolated. You can add a reference in your own plugin and use code similar to the following to get the HTML code or just the plain text.

Code Snippet
Win32EnumWindowsItem item = Win32EnumWindows.FindByClassName(owner.Handle, "Internet Explorer_Server");
if ((null != item) && !string.IsNullOrEmpty(Win32IEHelper.GetSelectedText(item.Handle)))
{
string selectedText = (whichSelectedTextFormatToGet ? Win32IEHelper.GetSelectedHtml(item.Handle)
: Win32IEHelper.GetSelectedText(item.Handle));
if (!string.IsNullOrEmpty(selectedText))
{
// Do whatever you want with selectedText and then return the modified text.
newContent = selectedText;
}
}

I am planning on releasing the code at some point once I get a chance to complete another plugin I am working on. However, there's just not enough time in the day... For now, this is an alternative.
LeoVildosola at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 7
Leo, three things
  1. Thanks for taking the time to respond with an example of usage!
  2. I do use your plugin for formatting religiously and its output peppers my blog, to that alone I owe you a debt of thanks. <g>
  3. Great way of thinking out of the box...does the WLW team know about this. <g>
OmegaMan at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...
# 8
Thanks for the feedback. The WLW Team does not know of the assembly but at least one of the members knows about me using some of these techniques for my Digg This plugin. I use it to prepopulate content in the plugin from text in the post. I do know that the title has changed method in the new version since they mentioned it as a defect when they were testing the Digg This plugin. So, I will have to change my logic at some point. Again, since this is a hack it is understandable that it is not supported, but it is all part of the game... Smile
LeoVildosola at 2007-9-25 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Writer: Development...

Windows Live Developer Forums

Site Classified