2

I'm trying to set up a temporary Sharepoint page that presents a form where users can enter some text and have it emailed off. So I have a page containing a form and a submit button that calls some JS to put the entered text into a SOAP request for Sharepoint, which adds it to a list and then sends an email containing that information. So far so good, and pretty painless.

The issue I'm having is that Outlook ignores any linebreaks that are part of the entered text. They're not being stripped out by anything, since I can use the 'View Source' option and see them normally in Notepad. I figure this is because Outlook's trying to display the message as HTML and doesn't know what to do with them. Ordinarily, I'd just throw in some JS that replaces all instances of \r\n with <br /> tags, but putting that into the SOAP request just results in anything following the tag being cut off before it gets added to the Sharepoint list.

Other things I've tried are

  • Adding a pair of spaces at the start of each new line (no change)
  • Added a second set of \r\n to every linebreak (no change)
  • Replaced all instances of \r\n with %0D%0A (displayed as text)
  • Replaced all instances of \r\n with \par (actually used \\par, to escape the first backslash). (displayed as text)
  • Appended \t to all instances of \r\n. (no change)
  • Prepended '.' to all instances of \r\n. (periods displayed, but linebreaks did not)

I'm working with Outlook 2007, Sharepoint 2007, and Internet Explorer 8.

I've read the questions:

This is the JS function I'm working with to edit the text, as well as create and POST the SOAP request. It's currently set up to place periods before each linebreak:

    function createAndPostSOAP(siteURL, listName)
    {
        var moreText = $("#MoreText")[0].innerText;

        var linebreakCount = moreText.match(/\r\n/g);

        moreText= "  " + moreText;
        for (var count = linebreakCount.length; count >= 0; count--)
        {
            moreText = moreText.replace("\r\n", ".[replace]");
        }

        while(moreText.indexOf("[replace]") != -1)
        {
            moreText = moreText.replace("[replace]", "\r\n");
        }

        var batch = 
            "<Batch OnError='Continue'> \
                    <Method ID='1' Cmd='New'> \
                        <Field Name='Text'>" + $("Text")[0].value + "</Field> \
                        <Field Name='MoreText'>" + moreText + "</Field> \
                    </Method> \
             </Batch>";

         var soapEnv =
                "<?xml version='1.0' encoding='utf-8'?> \
            <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
                xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
                xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
               <soap:Body> \
                <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                  <listName>" + listName + "</listName> \
                  <updates> \
                    " + batch + "</updates> \
                </UpdateListItems> \
              </soap:Body> \
            </soap:Envelope>";

        $.ajax({
        url: siteURL + "/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader    ("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=utf-8"
        }); 
    window.location='starting_page.htm';
    }

I'm mostly attacking this from the Javascript end, because I know that better than Sharepoint, but is there a way in Sharepoint 2007 to have a script change the linebreaks into <br /> once the data is already added to the column? Or is there an angle I missed in the Javascript?

Community
  • 1
  • 1
Angle O'Saxon
  • 176
  • 1
  • 7

1 Answers1

1

You need to encode all your HTML tags in the code. Meaning for

&amp; → & (ampersand)
&lt; → < (less-than sign)
&gt; → > (greater-than sign)
&quot; → " (quotation mark)
&apos; → ' (apostrophe)


Try the below code:

String Input = "adding this text <br/> this in next line <>";
String Output = Server.HtmlEncode(Input);
//

If required

Output = Output.Replace("\r\n", "<br />");
Anand
  • 197
  • 1
  • 7