1

我正在尝试使用 web 服务将记录插入到共享点列表中。一切正常,但是我无法上传带有描述的超链接,当我尝试上传它时,我给出了“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);
    }
4

1 回答 1

3

如果它是一个 URL 字段,则语法应该是:

<Field Name='UrlField'>http://stackoverflow.com/, stackoverflow</Field>

并注意后面的空格,,它很重要

于 2013-05-21T06:07:12.983 回答