[英]list.UpdateList method throwing an Exception “Microsoft.Sharepoint.SoapServerException”
[英]Adding items to a SharePoint list using UpdateList
我遇到了一个SharePoint问题,希望有人可以提供帮助。 基本上,当我尝试将名为“ MigratedChemist”的列添加到名为“ WorkCards”的列表(方法参数中的pListName)时。 无论我如何尝试,在调用UpdateList时都会出现FaultException错误。 我正在使用SharePoint Web服务进行连接。 我已经确认以下内容:
我的代码如下:
public static bool AddColumnToList(string pUri, string pListName, string pViewName, string pMaxRecords)
{
string version = string.Empty;
XAttribute xId = null;
XAttribute xVersion = null;
try
{
XElement listDetails = client.GetList(pListName);
xVersion = listDetails.Attribute("Version");
xId = listDetails.Attribute("ID");
}
catch { throw; }
XElement ndNewFields = new XElement ("Fields", "");
string newXml = "<Method ID='1' Cmd='New'><Field Name='MigratedChemist' Type='Text' DisplayName='MigratedChemist' /></Method></Fields>";
ndNewFields.Add(newXml);
XElement result;
try
{
result = client.UpdateList(xId.Value, null, ndNewFields, null, null, xVersion.Value);
}
catch (FaultException fe)
{
}
return true;
}
除此之外,还有人知道如何从FaultRequest中获取任何体面的信息吗? 目前,我收到以下错误消息,这是没有用的,并且似乎没有多余的细节。 我已经尝试过,因为有人建议删除错误处理并暂停程序,但这也没有给我任何额外的信息。
{“类型'Microsoft.SharePoint.SoapServer.SoapServerException'的异常被抛出。”}
供以后参考,我已经解决了SharePoint更新失败和FaultException问题的问题,因此为后代在此包括在内:
造成此问题的原因是我的XML格式错误。 当我调用ndNewFields.Add(newXml)时,返回的XML正在用控制字符替换<和>,如下所示(我添加了额外的空间,因为此编辑器会自动转换它们。
<Method ID =“ 1” Cmd =“ New”&gt;&lt;字段名称=“ MigratedChemist”&gt;&lt; / Field&gt;&lt; / Method&gt;
现在,我确实很早就注意到了这一点,但不确定是否会引起问题。 但是,使用XElement.Parse命令,我能够删除这些字符,从而解决了该问题:
ndNewFields.Add(XElement.Parse (newXml));
很久以来这一直困扰着我,所以很高兴我终于解决了它。 我不能相信它,就像我从另一页上摘下来的一样,但是下面的代码是我获得详细信息的方式。
catch (FaultException fe)
{
MessageFault msgFault = fe.CreateMessageFault();
XmlElement elm = msgFault.GetDetail<XmlElement>();
}
希望这会在将来节省一些人的挫败感!
安德鲁
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.