2011-04-20 63 views
0

我得到了一個代碼,使用Visual Studio 2010創建自定義SharePoint列表。但是,我可以在Visual Studio 2010中放置此代碼的位置在任何地方都沒有提及。有人可以幫我嗎?我真的很掙扎。這裏是代碼:在SharePoint列表中需要幫助。

using (SPSite oSPsite = new SPSite("http://Web URL")) 
{ 
    oSPsite.AllowUnsafeUpdates = true; 

    using (SPWeb oSPWeb = oSPsite.OpenWeb()) 
    { 
     oSPWeb.AllowUnsafeUpdates = true; 

     /* 1. create list from custom ListTemplate present within ListTemplateGalery */ 
     SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb); 
     SPListTemplate template = lstTemp["custom template name"]; 
     oSPWeb.Lists.Add("List Name", "Description", template); 

     /* 2. create list from sharepoint list content type (e.g. Links) */ 
     oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links); 
     oSPWeb.AllowUnsafeUpdates = false; 
    } 
    oSPsite.AllowUnsafeUpdates = false; 
} 

回答

1

你可以把它放在客戶端應用程序(控制檯,WinForms的,WPF)。唯一的限制是應用程序只能在SharePoint服務器上執行時才能使用。它不會遠程工作。

另一種方法是創建SharePoint功能並將其包含在Feature Receiver中。 Inside Microsoft SharePoint 2010的第3章介紹了構建Feature和附加Feature Receiver的過程。

http://msdn.microsoft.com/en-us/library/ff872401.aspx

+0

+1的功能接收

  • 運行,這就是我把它 – 2011-04-20 12:40:47

  • 0

    該代碼可以從根據要求,這裏的所有地方,你可以在SharePoint中執行代碼來執行一些

    1. 一個web部件即後面的代碼爲web部件
    2. 它可以是與背後的代碼運行的SharePoint頁面的一部分(http://blogs.msdn.com/b/kaevans/archive/2010/06/28/creating-a-sharepoint-site-page-with-code-behind-using-visual-studio-2010.aspx
    3. SharePoint定時工作http://blogs.msdn.com/b/guruketepalli/archive/2013/02/12/10259696.aspx
    4. 它可以是一個列表的事件處理程序/接收器的一部分,或者一個網絡事件接收器(http://msdn.microsoft.com/en-us/library/ff407274(v=office.14).aspx)從一些客戶端應用