1

I am trying to insert a record to a sharepoint list using the webservice. It all works fine however I can not upload a Hyperlink with Description, when I try to upload it, I am giving a "0x81020020 A URL field contains invalid data" error.

It works fine if I just upload the value http://www.somewebpage.com but I want it to have a description so I am trying to upload click here

I know it needs to be encoded.

        /// <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);
    }

1 Answer 1

3

If its a URL Field, the syntax should be:

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

And note the space after the , , its important

1
  • Yes its the name, UrlField is a placeholder. It will be Scanned_x0020_Timesheet in your case Commented May 21, 2013 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.