I'm trying to create a list item but the most basic formating is being removed from the input. Field type is Multiple lines of text and I've tried using Plain, Rick and Enhanced.

Script to create a list item and populate a field:

        $List = $Context.Web.Lists.GetByTitle($listTitle)

        $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation 
        $ListItem = $List.AddItem($ListItemInfo)

        $ListItem = $List.AddItem($ListItemInfo)
        $ListItem["Title"] = $myVar.Title
        $ListItem["BodyStuff"] = $myVar.SomeStuff   

myVar.SomeStuff is populated with the following

Hello blah,

This is a test message.

Thank you, blahblah

some other random text

When the item is created in SharePoint, the value of myVar.SomeStuff is compressed together removing any line breaks or formatting.

BodyStuff will look like this:
Hello blah, This is a test message. Thank you, blahblah some other random text

  • 1
    Have You tried using \r\n or <br> characters as line breaks? – Kristaps Vilerts Jun 13 '19 at 6:23
  • When using PlainText simple newlines (i.e. \r\n) are used. For RichText and "Enhanced" html is needed (i.e. <br>) – Nils Jun 13 '19 at 6:35
  • @KristapsVilerts yes, i tried it but it didn't work. Example: $desc = $myVar.SomeStuff.Replace("\r\n", "<br>") $ListItem["BodyStuff"] = $desc _____ also tried: $myVar.SomeStuff.ToString().Replace("\r\n", "<br>") – Taco_Buffet Jun 13 '19 at 14:36

Here's what I got to work.

$myVar.SomeStuff.Replace([Environment]::NewLine, "<br>")

@KristapsVilerts thank you for the input.

| improve this answer | |
  • Glad to hear that it worked! :) Please mark Your own answer as a "solution" via green check mark. – Kristaps Vilerts Jun 14 '19 at 5:40

While updating Multi line of text with HTML you have to pass html rather than just formatted text.

So in your case the SomeStuff should be html in form of string.

 $myVar.SomeStuff  ="<p>Hello blah,</p><p>This is a test message.</p><p>Thank you, blahblah</p><p>some other random text .....<span> text in span </span></p>";
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.