2011-04-20 88 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)从一些客户端应用