If watched my 10 min screencast on how to extend Server Explorer window with custom nodes – here comes the project code -> Habanero.DevTools.SHarePointExplorerTools
And here is a bit of a background.
The Visual Studio 2010 add-in will require Visual Studio 2010 RC and if you`re planning to customize the code make sure you have Visual Studio 2010 SDK RC installed; if you install incorrect version of SDK you won`t get any warning and run into strangest compile errors you`ve ever seen.
The solution functionality (adding additional nodes to Server Explorer) is in : Habanero.DevTools.WebPartNodeExtension
SiteNodeExtension.cs will ensure your nodes are created and webparts added to the tree, you`ll notice this class is marked as
[ExplorerNodeType(ExplorerNodeTypes.SiteNode)]
meaning it`s a Server Explorer extension that will trigger when you expand ExplorerNodeTypes.SiteNode. There are 2 more values you can choose from and the extension will trigger during different event appropriately.
Then we initialize our node and call a function to populate children:
nodeType.NodeChildrenRequested += NodeChildrenRequested;
WebPartNodeTypeProvider.cs is a going to populate the properties window with all the relevant properties as well as add new option to context menu of each webpart allowing user to copy the XML of the webpart to clipboard.
Here is the part that will set properties of the webpart to a properties window:
private void NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
{
var webPart = e.Node.Annotations.GetValue<ListItem>();
object propertySource = e.Node.Context.CreatePropertySourceObject(
webPart.FieldValuesAsText.FieldValues);
e.PropertySources.Add(propertySource);
}
Here is how I get a hold of the individual item upon `Copy XML` clicked and save it into clipboard:
if (parentNode != null)
{
var webPart = parentNode.Annotations.GetValue<ListItem>();
WebClient client = new WebClient();
Stream outputStream = new MemoryStream();
client.Credentials = CredentialCache.DefaultCredentials;
Stream webpartDef = null;
string documentUrl = string.Format(parentNode.Context.SiteUrl.AbsoluteUri
+ webPart.FieldValuesAsText.FieldValues["FileRef"]);
webpartDef = new MemoryStream(client.DownloadData(documentUrl));
using (StreamReader sr = new StreamReader(webpartDef))
{
Clipboard.SetText(sr.ReadToEnd());
}
MessageBox.Show(“Webpart XML copied to clipboard.”, “Webpart XML Copy”);
}
That`s it. Special thanks to MS on great documentation written on MSDN on this topic