0

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)
        $Context.Load($List)
        $Context.ExecuteQuery()

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

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

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

3
  • 1
    Have You tried using \r\n or <br> characters as line breaks? Jun 13, 2019 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, 2019 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>") Jun 13, 2019 at 14:36

2 Answers 2

1

Here's what I got to work.

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

@KristapsVilerts thank you for the input.

1
  • Glad to hear that it worked! :) Please mark Your own answer as a "solution" via green check mark. Jun 14, 2019 at 5:40
0

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>";

Your Answer

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

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