【发布时间】:2015-03-11 17:43:32
【问题描述】:
我正在尝试使用 winforms C# 应用程序将新项目添加到 Sharepoint 列表中,但我收到一个错误,好像该应用程序没有找到列表字段。
我的代码:
using SPC = Microsoft.SharePoint.Client;
(...)
string siteUrl = "https://sharepoint.company.com/sites/ProjectX";
SPC.ClientContext clientContext = new SPC.ClientContext(siteUrl);
string userName = "someone.surname";
SecureString password = new SecureString();
foreach (char c in "MyPaSsWoRd".ToCharArray()) password.AppendChar(c);
clientContext.Credentials = new NetworkCredential(userName, password, "MyDomain");
SPC.Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
SPC.List oList = web.Lists.GetByTitle("List Y");
clientContext.Load(oList);
clientContext.ExecuteQuery();
SPC.ListItemCreationInformation listCreationInformation = new SPC.ListItemCreationInformation();
SPC.ListItem oListItem = oList.AddItem(listCreationInformation);
oListItem["field 1"] = "a";
oListItem["field 2"] = "b";
oListItem["user"] = "someone.surname";
oListItem["date 1"] = "01/01/2015";
oListItem["field 3"] = "99";
oListItem.Update();
clientContext.ExecuteQuery();
最后一行代码出错:
列“字段 1”不存在。它可能已被其他人删除 用户。 /sites/ProjectX/Lists/List_Y
有什么建议吗?
PS.:是的,“列表 Y”上有一个名为“字段 1”的字段。
谢谢!
【问题讨论】:
-
也许您应该为您的列表write out the field names,以确保“字段 1”存在于 oList 对象中。
-
谢谢@wooters,但我已经这样做了,使用下面的行代码并且所有字段名称都可以:
SPC.FieldCollection FLDlist = oList.Fields; clientContext.Load(FLDlist); clientContext.ExecuteQuery(); string mmmsg = string.Empty; foreach (SPC.Field fld in FLDlist) { mmmsg += fld.Title + Environment.NewLine; } MessageBox.Show(mmmsg); -
看看这个SO post,如果你还没有。
-
对不起@wooters,但我不明白这一点:“sharepoint 询问你关于'信任'的问题,然后你必须选择你想要操作的列表”。我看不到任何来自共享点的“询问”或消息提示。
-
是的,说实话,我也不完全理解。它看起来与您正在处理的错误直接相关。
标签: c# winforms sharepoint sharepoint-2013