pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

Troubles setting Microsoft.SharePoint.Client.FieldUrlValue #1236

Open aslanovsergey opened 6 years ago

aslanovsergey commented 6 years ago

I run next chunk of code:

$item = Get-PnPFile -Url "Pages/folder/page1.aspx" -AsListItem
$item["Parent_x0020_Page"] = New-Object -TypeName Microsoft.SharePoint.Client.FieldUrlValue
$item["Parent_x0020_Page"].Url = "https://company.sharepoint.com/sites/Wiki/Pages/Licensing, Vendors, and Contracts/Licensing.aspx"
$item["Parent_x0020_Page"].Description = "/sites/Wiki/Pages/Licensing, Vendors, and Contracts/Licensing.aspx"
$item.Update()
Execute-PnPQuery

And I always get this result even when i tried different url format for Url property: _Execute-PnPQuery : Invalid URL: Microsoft.SharePoint.Client.FieldUrlValue. At line:1 char:1

My eventual goal is to set property "Parent_x0020_Page" for pages to "/sites/Wiki/Pages/Licensing, Vendors, and Contracts/Licensing.aspx".

I also tried next approach but it severs my url for url and description that breaks my url, the cause of this is commas so SharePoint thinks that i separated url and description by first comma. $item["Parent_x0020_Page"] = "/sites/Wiki/Pages/Licensing, Vendors, and Contracts/Licensing.aspx"

so eventually it becomes Description : Vendors, and Contracts/Licensing.aspx Url: https://company.sharepoint.com/sites/TechCorps-Wiki/Pages/Licensing TypeId: {fa8b44af-7b43-43f2-904a-bd319497011e}

Which version of the PnP-PowerShell Cmdlets are you using?

PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

Version : 2.20.1711.0

How did you install the PnP-PowerShell Cmdlets?

MSI Installed downloaded from GitHub

erwinvanhunen commented 6 years ago

Have you tried setting the comma as an encoded string?

$item["Parent_x0020_Page"].Url = "https://yoururl, Vendors%2C and Contracts/Licensing"

I haven't tried this personally though.