当然,前提是,你得拥有Visual Studio 2010,而且最好是装在服务器上面。听我的吧,这样可以避免很多问题,节省大量的时间。 这一讲介绍一下SharePoint Explorer
这个工具是集成在Server Explorer中的
很显然有了这个工具,就可以更好地理解一个SharePoint站点的结构了。目前这个工具,除了让开发人员更好地浏览SharePoint站点内容结构之外,如果我们在Lists上面去点击右键的话,还可以直接点位到该列表
下面是有一个例子
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Windows.Forms;
using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;
namespace Contoso.ServerExplorerExtension
{
[Export(typeof(IExplorerNodeTypeExtension))]
[ExplorerNodeType(ExplorerNodeTypes.SiteNode)]
internal class SiteNodeExtensionWithContextMenu : IExplorerNodeTypeExtension
{
public void Initialize(IExplorerNodeType nodeType)
{
nodeType.NodeMenuItemsRequested += nodeType_NodeMenuItemsRequested;
}
void nodeType_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
{
IMenuItem menuItem = e.MenuItems.Add("Display Message");
menuItem.Click += menuItem_Click;
}
void menuItem_Click(object sender, MenuItemEventArgs e)
{
IExplorerNode node = (IExplorerNode)e.Owner;
MessageBox.Show(string.Format("Clicked the menu item for the '{0}' node.", node.Text));
}
}
[Export(typeof(IExplorerNodeTypeExtension))]
[ExplorerNodeType(ExtensionNodeTypes.FieldNode)]
internal class FieldNodeExtensionWithProperty : IExplorerNodeTypeExtension
{
public void Initialize(IExplorerNodeType nodeType)
{
nodeType.NodePropertiesRequested += nodeType_NodePropertiesRequested;
}
void nodeType_NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
{
// Only add the property to "Body" fields.
if (e.Node.Text == "Body")
{
ExampleProperty propertyObject;
// If the properties object already exists for this node, get it from the node's annotations.
if (!e.Node.Annotations.TryGetValue(out propertyObject))
{
// Otherwise, create a new properties object and add it to the annotations.
propertyObject = new ExampleProperty(e.Node);
e.Node.Annotations.Add(propertyObject);
}
e.PropertySources.Add(propertyObject);
}
}
}
internal class ExampleProperty
{
private IExplorerNode node;
private const string propertyId = "Contoso.ExampleProperty";
private const string propertyDefaultValue = "This is an example property.";
internal ExampleProperty(IExplorerNode node)
{
this.node = node;
}
// Gets or sets a simple string property.
[DisplayName("ContosoExampleProperty")]
[DescriptionAttribute("This is an example property for field nodes.")]
[DefaultValue(propertyDefaultValue)]
public string TestProperty
{
get
{
string propertyValue;
// Get the current property value if it already exists; otherwise, return a default value.
if (!node.Annotations.TryGetValue(propertyId, out propertyValue))
{
propertyValue = propertyDefaultValue;
}
return propertyValue;
}
set
{
if (value != propertyDefaultValue)
{
// Store the property value in the Annotations property of the node.
// Data in the Annotations property does not persist when Visual Studio exits.
node.Annotations[propertyId] = value;
}
else
{
// Do not save the default value.
node.Annotations.Remove(propertyId);
}
}
}
}
}