Sharepoint:从项目事件处理程序创建子网站

Sharepoint:从项目事件处理程序创建子网站,sharepoint,sharepoint-2010,spweb,Sharepoint,Sharepoint 2010,Spweb,我有一个“项目列表”(标题、领导、成员、站点URL),它应该是指包含项目列表的站点下的团队站点。因此,我在沙盒解决方案的功能中添加了一个SPItemEventReceiver 在项目添加(属性)中,我调用以下命令: string projectName = properties.AfterProperties["Title"].ToString(); SPWeb currentWeb = properties.Web; SPWeb subweb = currentWeb.Webs.Add(pro

我有一个“项目列表”(标题、领导、成员、站点URL),它应该是指包含项目列表的站点下的团队站点。因此,我在沙盒解决方案的功能中添加了一个
SPItemEventReceiver

项目添加(属性)
中,我调用以下命令:

string projectName = properties.AfterProperties["Title"].ToString();
SPWeb currentWeb = properties.Web;
SPWeb subweb = currentWeb.Webs.Add(projectName, projectName, 
  "Project site for " + projectName, (uint) currentWeb.Locale.LCID, 
  Microsoft.SharePoint.SPWebTemplate.WebTemplateSTS, true, false);
但在调试时,调用Add会抛出一个
SPException
为的HResult代码包装一个COMException,该代码失败,并显示消息沙盒代码执行请求被拒绝,因为沙盒代码主机服务太忙,无法处理该请求

参数是否有问题,或者我应该将实际创建委托给工作流吗?

请尝试以下方法: 公共覆盖无效项添加(SPItemEventProperties属性) { 基本项添加(属性)


似乎出现了一些死锁情况;我通过使用post event ItemAdded解决了我的特殊情况(从AfterProperties中的设置值改为更新ListItem)。由于某些原因,对Webs.Add()的调用正常完成…

嗯,它退出得更快,因为“此服务器不支持该语言”:)将该参数更改为currentWeb.Language会出现相同的错误;我所做的另一个更改是使用OpenWeb()而不是仅获取Web属性,并将创建调用放入using语句中。还尝试了字符串“STS#0”文档状态是团队站点的字符串值…嗨,我面临同样的问题。你能展示一下最终结果吗?Webs.Add()调用开始,但从未结束。在SP Designer中查看子网站列表时,我看到一个网站有URL,但没有标题和内容。我的代码与此非常相似:很抱歉,该代码已替换为对SPSite.SelfServiceCreateSite()的调用,以避免用户运行相关代码时出现问题(由Microsoft推荐)。请注意,在这种情况下,您需要传递两个用户,这两个用户将成为主网站集管理员和辅助网站集管理员。此外,还发现,如果使用RunWithElevatedPrivileges(),则需要为SPSite等创建新对象,而不是重用在该代码之外创建的对象。
          // Get the web where the event was raised
          SPWeb spCurrentSite = properties.OpenWeb();

          //Get the name of the list where the event was raised          
          String curListName = properties.ListTitle;

          //If the list is our list named SubSites the create a new subsite directly below the current site
          if (curListName == "SubSites")
          {
              //Get the SPListItem object that raised the event
              SPListItem curItem = properties.ListItem;
              //Get the Title field from this item. This will be the name of our new subsite
              String curItemSiteName = properties.AfterProperties["Title"].ToString();
              //Get the Description field from this item. This will be the description for our new subsite
              string curItemDescription = properties.AfterProperties["Description"].ToString();
              //Update the SiteUrl field of the item, this is the URL of our new subsite
              properties.AfterProperties["SiteUrl"] = spCurrentSite.Url + "/" + curItemSiteName;

              //Create the subsite based on the template from the Solution Gallery
              SPWeb newSite = spCurrentSite.Webs.Add(curItemSiteName, curItemSiteName, curItemDescription, Convert.ToUInt16(1033), "{8FCAD92C-EF01-4127-A0B6-23008C67BA26}#1TestProject", false, false);
                 //Set the new subsite to inherit it's top navigation from the parent site, Usefalse if you do not want this.
                 newSite.Navigation.UseShared = true;
                 newSite.Close();


           }
      }