2009-10-23 69 views
0

我是在網站集下創建子網站的控制檯應用程序 網站集只接受基於表單的用戶。Sharepoint表單身份驗證使用其他帳戶運行

現在,當我運行控制檯應用程序,它與Windows憑據。

我需要某種方式來運行控制檯應用程序中的代碼,該代碼創建子站點,以便在管理該網站集的窗體用戶下運行。

請讓我知道您的建議。

感謝

回答

0

您需要創建管理中心Web應用程序([12蜂巢] \ AMDISAPI)內一個新的Web服務,並添加創建子網站的功能。

下面是一個例子 - 從SharePoint for Hosters項目hstCreateSubSite功能:

/// <summary> 
/// Method to create a Sub site for a site collection 
/// </summary> 
/// <param name="strSiteURL">url of the sitecollection i.e. "http://www.sitea.com"</param> 
/// <param name="subsitePath">the path to the subsite i.e. inventory</param> 
/// <param name="strTitle">sub site title</param> 
/// <param name="strDesc">sub site description</param> 
/// <param name="strTemplate">a valid templateID</param> 
/// <param name="nLCID">the LCID for the language i.e. 1033 for english</param> 
[WebMethod] 
public void hstCreateSubSite(string strSiteURL, string subSitePath, string strTitle, string strDesc, string strTemplate, uint nLCID) 
{ 

    SPSite oSite = new SPSite(strSiteURL); 
    SPWeb oSubSiteWeb = oSite.OpenWeb(); 

    SPWeb oWeb = null; 

    if (String.IsNullOrEmpty(strDesc)) strDesc = null; 
    if (String.IsNullOrEmpty(strTitle)) strTitle = null; 

    try 
    { 
     // elevate permissions to allow user to create a new site. 
     SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 
      // the subsite will inherit permissions and will not convert the site if it exists 
      oWeb = oSubSiteWeb.Webs.Add(subSitePath, strTitle, strDesc, nLCID, strTemplate, false, false); 

      SPNavigationNodeCollection nodes = oSubSiteWeb.Navigation.TopNavigationBar; 
      SPNavigationNode navNode = new SPNavigationNode(strTitle, subSitePath); 
      nodes.AddAsLast(navNode); 

      oWeb.Navigation.UseShared = true; 

      // create entry in property bag to store template and url in the subsite. 
      oWeb.AllowUnsafeUpdates = true; 
      // add the Templateid to the property bag. This needs to be done becuase 
      // sites that are created from site templates (.stp) do not retain the templateid. 
      oWeb.Properties.Add("STP_ID", strTemplate); 
      oWeb.Properties.Update(); 
      oWeb.AllowUnsafeUpdates = false; 

     }); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
    finally 
    { 
     //dispose objects 
     if (oWeb != null) 
      oWeb.Dispose(); 

     if (oSite != null) 
      oSite.Dispose(); 
    } 
} 
相關問題