繁体   English   中英

在C#中创建Sharepoint网站

[英]Creating Sharepoint Site in C#

我正在尝试使用Sharepoint客户端名称空间创建一个Sharepoint网站,下面是完整代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    private void button1_Click(object sender, EventArgs e)
    {

        SPSite topLevelSite = new SPSite("http://localhost");
        SPWeb spWebInstance = topLevelSite.OpenWeb();
        String siteTemplate = spWebInstance.WebTemplate;
        try
        {
            SharePointWebInstance.Webs.Add("the name", "name", "new site added", (UInt32)System.Globalization.CultureInfo.CurrentCulture.LCID, siteTemplate, false, false);
        }
        catch (Exception ex)
        {
            //...
        }
        finally
        {
            topLevelSite.Close();
            SharePointWebInstance.Dispose();
        }
    }
}

}

我在SharePointWebInstance.Webs.Add遇到C#错误。 有什么想法吗?

您需要使用已创建的SPWeb对象,因此应该像这样;

spWebInstance.Webs.Add("the name", "name", "new site added", (UInt32)System.Globalization.CultureInfo.CurrentCulture.LCID, siteTemplate, false, false);

并确保相应地更新SPSite URL地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM