我在asp.net中调用SharePoint Web服务。以下是我的代码。其中 EmpPortal 是服务引用的名称。
EmpPortal.Lists L = new EmpPortal.Lists();
L.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndQueryOptions.InnerXml =
"<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
"<DateInUtc>TRUE</DateInUtc>";
ndViewFields.InnerXml = "<FieldRef Name='ows_Calendar Type' />" +
"<FieldRef Name='ows_Title'/>" +
"<FieldRef Name='ows_Holiday Type'/>" +
"<FieldRef Name='ows_Day'/>" +
"<FieldRef Name='ows_Holiday Date'/>";
ndQuery.InnerXml = "<Where><Gt><FieldRef Name='ows_Holiday Date'/>" +
"<Value Type= 'DateTime'>2014-01-01T00:00:00</Value></Gt></Where>";
XmlNode n = L.GetListItems("Holidays", null, ndQuery,ndViewFields ,null,ndQueryOptions, null);
我在FieldRef标签中应该给出的名称面临问题。 因为这个代码我得到了异常: 'Microsoft.SharePoint.SoapServer.SoapServerException'
那么请更清楚地了解Lists.GetListItems()
的参数?
以及如何将它们用于我的代码。
答案 0 :(得分:1)
ndViewFields.InnerXml = "<FieldRef Name= 'Calendar Type' />" +
"<FieldRef Name='Title'/>" +
"<FieldRef Name='Holiday Type' />" +//HERE SPACE IS THERE IN BETWEEN WORDS
"<FieldRef Name='Day'/>" +
"<FieldRef Name='Holiday Date'/>"; //HERE SPACE IS THERE IN BETWEEN WORDS
ndQuery.InnerXml = String.Format("<Where><Gt><FieldRef Name='Holiday_x0020_Date'></FieldRef><Value Type='DateTime'>2014-01-01T00:00:00</Value></Gt></Where>");
所需的主要更改是将带有前缀和后缀的x0020替换为SPACE,如上面的代码所示。