![](/img/trans.png)
[英]How to add new items to SharePoint List using List.asmx native WebService and client object model?
[英]Adding Hyperlink Description to Sharepoint using webservice list.asmx
我正在尝试使用webservice将记录插入到sharepoint列表中。 这一切都运行良好,但我无法上传带说明的超链接,当我尝试上传它时,我给出了“0x81020020一个URL字段包含无效数据”错误。
如果我只是上传值http://www.somewebpage.com但它希望它有一个描述所以我试图上传点击这里它工作正常
我知道它需要编码。
/// <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);
}
如果是URL字段,则语法应为:
<Field Name='UrlField'>http://stackoverflow.com/, stackoverflow</Field>
并注意后的空间,
其重要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.