我正在尝试使用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#错误。有什么想法吗?
答案 0 :(得分:0)
您需要使用已创建的SPWeb对象,所以应该像这样;
spWebInstance.Webs.Add("the name", "name", "new site added", (UInt32)System.Globalization.CultureInfo.CurrentCulture.LCID, siteTemplate, false, false);
还要确保相应地更新SPSite网址。