我正在尝试使用webservice将记录插入到sharepoint列表中。一切正常,但我无法上传带描述的超链接,当我尝试上传时,我给出了“0x81020020一个URL字段包含无效数据”错误。
如果我只是上传了值http://www.somewebpage.com,但是我希望它有描述,那么我正在尝试上传click here
我知道它需要编码。
/// <summary>
/// Insert Record to Sharepoint
/// </summary>
public void InsertDayRecord(Drivers Driver, string startTime, string FinishTime, string breakTime, string totalHours, Equipment truck, Equipment trailer,
string hoursType, bool overNight, string notes, string documentUrl)
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
//encode notes
notes = System.Net.WebUtility.HtmlEncode(notes);
//Add url to link to display description - this causes error
string url = "<a href=\"" + documentUrl + "\">download</a>";
url = System.Net.WebUtility.HtmlEncode(url);
//Build XML
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>{0}</Field><Field Name='Start_x0020_Time'>{1}</Field>", Driver.DriverName, startTime);
sb.AppendFormat("<Field Name='Finish_x0020_Time'>{0}</Field><Field Name='Break_x0020__x0028_Minutes_x0029'>{1}</Field>", FinishTime, breakTime);
sb.AppendFormat("<Field Name='Total_x0020_Hours'>{0}</Field><Field Name='Truck'>{1}</Field>", totalHours, truck.EquipmentWithId);
sb.AppendFormat("<Field Name='Over_x0020_Night'>{0}</Field><Field Name='Notes'>{1}</Field>", overNight.ToString(), notes);
sb.AppendFormat("<Field Name='Trailer'>{0}</Field><Field Name='Driver'>{1}</Field>", trailer.EquipmentWithId, Driver.DriverWithId);
//If file is uploaded add hyperlink
if (documentUrl != string.Empty)
sb.AppendFormat("<Field Name='Scanned_x0020_Timesheet'>{0}</Field>", url);
sb.AppendFormat("<Field Name='Hours_x0020_Type'>{0}</Field>", hoursType);
sb.Append("</Method>");
elBatch.InnerXml = sb.ToString();
//upload to sharepoint via lists.asmx
XmlNode Success = GetService().UpdateListItems("TimeSheets", elBatch);
}
答案 0 :(得分:2)
如果是URL字段,则语法应为:
<Field Name='UrlField'>http://stackoverflow.com/, stackoverflow</Field>
请注意,
之后的空格,重要的是