Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

InfoPath – search replace URLs within XSN

Need to migrate forms to another URL?   But not sure how to update many data connections?  Try the script below.

This PowerShell will extract XSN contents to a folder, execute string search replace, and “package” back into CAB format with XSN extension.   A simple way to migrate InfoPath forms to another DNS name for scenarios like AAM Alternate Access Mapping redirection and SharePoint major version upgrade (2007 > 2010 > 2013).

Enjoy! 

shades_smile

 

NOTE – Requires CABARC.EXE  http://stackoverflow.com/questions/3361928/where-can-i-get-the-cabarc-utility

 

InfoPath_UpdateDataConnetions.ps1

# Update InfoPath form URLs by extracting CAB and performing search replace
Param(
	[string]$xsnFile
)
Write-Host "Prepare folders..."
md c:\InfoPath\before
md c:\InfoPath\temp
md c:\InfoPath\after
Write-Host "Clean temp..."
Remove-ChildItem c:\InfoPath\temp\*.* -Recurse
Write-Host "Extract XSN... $xsnFile"
cabarc x "c:\InfoPath\before\$xsnFile" *.* c:\InfoPath\temp\
Write-Host "Replace URL..."
$txt = Get-Content c:\InfoPath\temp\Manifest.xsf
$txt |% {$_ -replace "//sharepoint/" "//sharepnt07/"} | Out-File -FilePath "c:\InfoPath\temp\Manifest.xsf" -Encoding UTF8 -Force
Write-Host "package XSN..."
cabarc n "c:\InfoPath\after\$xsnFile" c:\InfoPath\temp\*.*
Write-Host "DONE"

 

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲