在SharePoint 2010中以编程方式创建Wiki网站时如何设置URL?

时间:2011-02-01 22:23:52

标签: sharepoint sharepoint-2010

我正在创建一个新网站:

SPSite currentContext = SPContext.GetContext(HttpContext.Current).Site;
SPWeb parentID = currentContext.OpenWeb(new Guid(parentSiteValue));

newWeb = parentID.Webs.Add(newSiteUrl, newSiteName, null, (uint)1033, siteTemplate, true, false);

siteTemplate是我在下拉列表中选择的模板,当我从团队网站模板或类似地创建网站时它可以正常创建网站但是当创建维基站点时,实际的URL是/pages/home.aspx下的父网站,但如果我将此添加到newSiteUrl我得到错误,如不能有斜杠,文件夹不存在等等。

如何创建Wiki网站并以编程方式设置网址?

提前致谢。

修改 将URL设置为 newSiteUrl = newSiteName +“/ pages /” 给了我

"testpage/pages/" contains leading or trailing slash, which is invalid.

newSiteUrl = newSiteName +“/ pages”

The folder that would hold URL '/dept/class/wikitest/pages' 
does not exist on the server.

newSiteUrl = newSiteName +“/ pages / home.aspx”

The URL '/dept/class/wikitest/pages/home.aspx' is invalid. 
It may refer to a nonexistent file or folder, 
or refer to a valid file or folder that is not in the current Web.

2 个答案:

答案 0 :(得分:0)

我在这里发布了你的问题的答案:http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/e25f10ef-bdd9-4445-8508-67b58c2396f9希望这有帮助!

乔尔

joelblogs.co.uk

答案 1 :(得分:0)

您可以这样设置网址:

using (SPSite site = new SPSite("http://localhost"))
{
    string parentWebName = "MyOrganization";
    using (SPWeb parentWeb = site.OpenWeb())
    {
        string webTitle = "DepartMent Wiki";
        string webDesc = "DepartMent Wiki";     string webName = "HRWiki";
        string webUrl = String.Format("{0}/{1}", parentWebName, webName);
        uint webLcid = parentWeb.Language;

        // Name value for the Document Workspace template.
        string webTemplateName = "STS#4";

        SPWeb newWeb = null;

        // Create the new web.
        try
        {
            newWeb = site.AllWebs.Add(webUrl, webTitle, webDesc, webLcid, webTemplateName, false, false);

            SPFolder rootFolder = newWeb.RootFolder; 
            rootFolder.WelcomePage = "My Wiki Library/MyWelcome.aspx";
            rootFolder.Update();
        }
        catch (ArgumentException ex)
        {
        }
    }
}
希望这有帮助。