Sharepoint 2010 需要SharePoint列表中的帮助。

Sharepoint 2010 需要SharePoint列表中的帮助。,sharepoint-2010,Sharepoint 2010,我得到了一个使用VisualStudio2010创建自定义SharePoint列表的代码。但我在哪里可以把这段代码放在VisualStudio2010中并没有提到任何地方。谁能帮帮我吗?我真的很挣扎。代码如下: using (SPSite oSPsite = new SPSite("http://Web URL")) { oSPsite.AllowUnsafeUpdates = true; using (SPWeb oSPWeb = oSPsite.OpenWeb())

我得到了一个使用VisualStudio2010创建自定义SharePoint列表的代码。但我在哪里可以把这段代码放在VisualStudio2010中并没有提到任何地方。谁能帮帮我吗?我真的很挣扎。代码如下:

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

您可以将其放在客户端应用程序(控制台、WinForms、WPF)中。唯一的限制是,应用程序只有在SharePoint服务器上执行时才能工作。它不能远程工作

另一种方法是创建SharePoint功能并将代码包含在功能接收器中。Microsoft SharePoint 2010内部的第3章介绍了构建功能和附加功能接收器的过程


此代码可以在sharepoint中执行代码的所有位置执行,具体取决于需求,以下是一些

  • 一个Web部件,即该Web部件的代码
  • 它可以是使用代码隐藏()运行的sharepoint页面的一部分
  • SharePoint计时器作业
  • 它可以是列表事件处理程序/接收器或web事件接收器()的一部分
  • 从某个客户端应用程序运行