天天看點

MOSS 2010:Visual Studio 2010開發體驗(1)——SharePoint Explorer

你不得不感概,原先在MOSS 2007的時代我們是多麼辛苦。不是嗎?

  • Visual Studio 開發體驗受到局限

    适用于 WSS 的 Visual Studio 擴充

    Visual Studio Tools for Office 與 VS2008 之間的配合

    SharePoint 開發人員需要依賴于社群工具

  • 開發人員不得不應對層出不窮的細節工作

    手工編輯 CAML 檔案

    熟悉 WSS 的 RootFiles 目錄

    手工編輯 manifest.xml 檔案

    為解決方案包建構 .wsp 檔案

是的 ,對這些痛苦我們記憶猶新。好吧,現在是時候改變了

  • SharePoint 2010 采用端到端的開發體驗

    用于浏覽網站的 SharePoint Explorer

    SharePoint 2010 項目與元件模闆

    适用于各種主要應用場景的可視化設計環境

    為 Visual Studio 2008 for WSS 3.0 提供遷移路徑

    可由第三方開發人員進行擴充

  • SharePoint 開發人員的好消息

    實作 RootFiles 目錄細節的簡化

    實作 .wsp 檔案建構工作的簡化

    減少/避免對外部工具的使用需求

當然,前提是,你得擁有Visual Studio 2010,而且最好是裝在伺服器上面。聽我的吧,這樣可以避免很多問題,節省大量的時間。

這一講介紹一下SharePoint Explorer

這個工具是內建在Server Explorer中的

MOSS 2010:Visual Studio 2010開發體驗(1)——SharePoint Explorer
MOSS 2010:Visual Studio 2010開發體驗(1)——SharePoint Explorer

很顯然有了這個工具,就可以更好地了解一個SharePoint站點的結構了。目前這個工具,除了讓開發人員更好地浏覽SharePoint站點内容結構之外,如果我們在Lists上面去點選右鍵的話,還可以直接點位到該清單

MOSS 2010:Visual Studio 2010開發體驗(1)——SharePoint Explorer

我覺得這個工具還不是很完善,以後可能會更加強一些。例如直接可以拖拽到程式界面上這樣的功能

關于 Explorer的擴充,如果有興趣的朋友,可以參考下面的連結

http://msdn.microsoft.com/en-us/library/ee471438(VS.100).aspx

下面是有一個例子

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);
                }
            }
        }
    }

}
           

繼續閱讀