Greg Pelle

Hello,

I am trying to add an item to a task list using the web services. The item adds correctly, except for the description field. The description field contains the data I expect, just not formatted.

In the description field I see the following:

line1 line2 line3 line4 line5

but I want to see:

line1

line2

line3

line4

I am using the StringBuilder class AppendLine method to format my description string:

StringBuilder description = new StringBuilder();

description.AppendLine("Old Address:");

description.AppendLine(oldAddress);

description.AppendLine();

description.AppendLine("New Address:");

description.AppendLine(newAddress);

The string output is then fed into another string builder that assembles the XML that is fed to the UpdateListItems method.

XmlDocument doc = new XmlDocument();

XmlElement root = doc.CreateElement("Batch");

root.SetAttribute("OnError", "Continue");

root.SetAttribute("ListVersion", listVersion);

StringBuilder sb = new StringBuilder("<Method ID='1' Cmd='New'>");

sb.Append("<Field Name='ID'>New</Field>");

sb.Append("<Field Name='ows_LinkTitle'>");

sb.Append(EscapeIllegalCharacters(title));

sb.Append("</Field><Field Name='Title'>");

sb.Append(EscapeIllegalCharacters(title));

sb.Append("</Field><Field Name='Body'>");

sb.Append(EscapeIllegalCharacters(description.ToString()));

sb.Append("</Field></Method>");

root.InnerXml = sb.ToString();

XmlNode resultsNode = ourLists.UpdateListItems(listGUID, root);

Any ideas on what I am doing wrong

Greg.



Re: SharePoint - Development and Programming Multi line task item using web services

Ishai Sagi

Try putting each line in a "<div>" tag. I think that is how it is parsed.




Re: SharePoint - Development and Programming Multi line task item using web services

Greg Pelle

I put in the required <div></div>tags as follows:

StringBuilder description = new StringBuilder();

description.AppendLine("<div>Old Address:");

description.AppendLine(oldAddress);

description.AppendLine("</div><div>");

description.AppendLine("New Address:");

description.AppendLine(newAddress);

description.AppendLine("</div>");

The div tags are now displayed in the Description field. I also tried wrapping the multi line data in CDATA, but that also does not work.





Re: SharePoint - Development and Programming Multi line task item using web services

Chase M

Try 'XmlEncoding' the <div/> or any other html markup when adding it to your XmlNode of field values.

Here's a function I use to do this (does anyone know if .NET has a built in XmlEncode or Decode function )

private string EncodeXML(string value)

{

return (value.Replace("&", "&amp;").Replace("'", "&apos;").Replace(">", "&gt;").Replace("<", "&lt;")

.Replace("\"", "&quot;"));

}

The idea is to replace Xml reserved characters with their xml equivalents.

I have a couple of applications that load new list items into using the web services and I have to use this for any HTML content I upload.

Chase





Re: SharePoint - Development and Programming Multi line task item using web services

Greg Pelle

I am already doing something similar using Regex.Replace.

I am able to upload HTML content to the field, but it shows unformatted (no line breaks, no h1's etc...).

You state that you have a couple of applications that load new list items using the web services. Do any of them display formatted text in the default description field The list I am trying to insert items into was created using the Task List with no modifications.

Greg.





Re: SharePoint - Development and Programming Multi line task item using web services

Chase M

The lists I load items into are custom lists. The fields that I'm able to get HTML into are the same type as the default Task list's Description field though: Multiple lines of text with the option for Allow rich HTML text on (this is SPS 2003).

Hmmm...

I sent this to the Lists web service (on a default Tasks list):

<SOAP-ENV:Envelope xmlnsTongue TiedOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlnsTongue TiedOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<SOAP-ENV:Body>

<m:UpdateListItems xmlns:m="http://schemas.microsoft.com/sharepoint/soap/">

<m:listName>Tasks</m:listName>

<m:updates>

<Batch OnError="Continue">

<Method ID="0" Cmd="New">

<Field Name="Title">New Task From Web Service</Field>

<Field Name="Body">A &lt;b&gt;BOLD&lt;/b&gt;&lt;br/&gt;new task</Field>

</Method>

</Batch>

</m:updates>

</m:UpdateListItems>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

And when I viewed the task the Description displayed properly (BOLD was bold and there was a line break after it)

Can you post a sample soap request

Chase





Re: SharePoint - Development and Programming Multi line task item using web services

Greg Pelle

Here is my soap request:

soap:Envelope xmlnsTongue Tiedoap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>{FA11CD4F-3D4C-4B66-8662-89E077DD0F54}</listName>
<updates>
<Batch OnError="Continue" ListVersion="1" xmlns="">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="ows_LinkTitle">New Item</Field>
<Field Name="Title">New Item</Field>
<Field Name="Body">&amp;lt;h1&amp;gt;This is the item&amp;lt;/h1&amp;gt;</Field>
</Method>
</Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>

Comparing the two requests, I have extra '&' characters in my request. I will look into it further.

Greg.





Re: SharePoint - Development and Programming Multi line task item using web services

Greg Pelle

I found the problem. I was encoding my characters in the wrong order.

What should have been &lt; was being encoded again into &amp;lt;. I fixed the issue and all is working.

Thanks.

Greg.