我试图使用C#在Sharepoint中添加项目到列表项,但后来又出现了这个错误
未处理的类型' System.InvalidOperationException' 发生在Microsoft.SharePoint.dll
行
中指出的错误using (SPSite site = new SPSite(SiteUrl))
以下是代码:
private const string SiteUrl = "http://sp2013train2:12877/test/";
private const string ListName = "Category";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SPSite site = new SPSite(SiteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList(ListName);
SPListItem newItem = list.Items.Add();
// notice that Project Name Column still referring to Title column even though we have changed that
newItem["Title"] = textBox1.Text;
newItem.Update();
}
}
}
任何帮助都会有所帮助,谢谢你提前
答案 0 :(得分:0)
尝试以下方法:
web.AllowUnsafeUpdates = true;
SPList list = web.Lists.TryGetList(ListName);
SPListItem newItem = list.Items.Add();
// notice that Project Name Column still referring to Title column even though we have changed that
newItem["Title"] = textBox1.Text;
newItem.Update();
web.allowUnsafeUpdates = false;
答案 1 :(得分:0)
我通过从ISAPI文件夹添加dll来解决同样的问题。 我错了microsoft.sharepoint.dll
此致 Prafulla