I want to get xml of an infopath item in sharepoint 2010 with Powershell but it seems the xml file is not found inside the item How to fix that

263 views Asked by At

I have a two envirment a dev envirment and a prod envirement, I have built a Powershell script to get the xml text of an infopath item inside a form library it works fine in the dev envirment but when i have tried it in the prod envirment, it send back an error message that indicate the File field of the item is null, is that possible with InfoPath ? In the full script I can edit a field of an infopath item with powershell.

#Params
$WebURL = Read-Host 'WebURL '
$InfoPathLibraryName = Read-Host 'InfoPathLibraryName '
$ItemID = Read-Host 'ItemID '

#Get Objects
$web = Get-SPWeb $WebURL
$InfoPathLibrary = $web.Lists[$InfoPathLibraryName]
$Item = $InfoPathLibrary.GetItemById($ItemID)
Write-Output $Item

#Execution
$file = $Item.File
$data = $file.OpenBinary()
$encode = New-Object System.Text.UTF8Encoding
$uu = $encode.GetString($data)
Write-Output $uu

PowerShell error Message

1

There are 1 answers

0
Abhijeet Jadhav On

Were you able to retrieve the list $Item correctly? Try below :

$Item = $InfoPathLibrary.GetItemById(Convert.ToInt32($ItemID))