Showing posts with label Migration. Show all posts
Showing posts with label Migration. Show all posts

Tuesday, December 6, 2016

Find things in InfoPath form templates in a web application

This assessment and clean up process to get things ready for SharePoint online migration is pretty interesting.   So there are some custom web services created for InfoPath forms so that it can get data and functions (lots of date functions) that is not available out of the box.   So need to find all the published templates with the calls to these web services.

So after thinking about what can be done with code and reviewing the InfoPath interop classes leading nowhere.   I found an interesting article https://sharepintblog.com/2011/06/07/updating-infopath-form-templates-and-data-connections-with-powershell/

so with the code that they provided, i modified it to spit out all templates with the data connections to these web services.  

Hope this helps since it is saving a lot of time and effort to track these down and find a workaround.

--updated with the code to include list templates not just document libraries. 

Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

## the web application to be searched for form libraries
$url = 'https://yoursharepointurl'

## temp working directory
$dir = 'D:\ExtractedForms'


$findstring = 'findthis String'

$exportFile = $false

foreach ($web in (Get-SPWebApplication $url | Get-SPSite -Limit All| Get-SPWeb -Limit All))
{
    foreach($list in $web.Lists)
    { 
        if ($list.DocumentTemplateUrl -ne $null -or $list.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"])
        {
            if ($list.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"])
            {
                #--------------- get the templateurl for the list template....  
                foreach($folder in $list.RootFolder.SubFolders)
                {
                    foreach($file in $folder.Files)
                    {
                        if($file.Name -eq 'template.xsn')
                        {
                            $listUrl = $web.Url + '/' + $list.RootFolder + '/' + $folder.Name
                            $templateUrl = $web.Url + '/' + $list.RootFolder + '/' + $folder.Name +'/template.xsn'

                            $exportFile = $true 
                        }
                    }               
                }             
                                          
            }
            elseif ($list.DocumentTemplateUrl.ToString().ToLower().EndsWith(".xsn"))
            {
                $listUrl = $web.Url + '/' + $list.rootFolder
                $templateUrl = $web.Url + '/' + $list.DocumentTemplateUrl

                $exportFile = $true 
            }

            if($exportFile)
            {
                ## download the form template
                $filename = $file.Name
                $fileID = $file.UniqueId.Tostring()
                $localfile = $fileID + "\" + $filename

                $file = $web.GetFile($templateUrl)
                $bytes = $file.OpenBinary();

                # Download the file to the path
                $localfile = $dir + "\" + $localfile
                New-Item "$dir\$fileID" -type directory -force | Out-Null
                New-Item "$dir\$fileID\Extracted" -type directory -force | Out-Null
                [System.IO.FileStream] $fs = New-Object System.IO.FileStream($localfile, "OpenOrCreate")
                $fs.Write($bytes, 0 , $bytes.Length)
                $fs.Close()
            
                ## crack open the form template
                EXPAND "$localfile" -F:* "$dir\$fileID\Extracted" | Out-Null
                
                ## get file content and check for string
                $extractedFiles = Get-ChildItem "$dir\$fileID\Extracted" *.x*
                foreach ($extractedFile in $extractedFiles)
                {
                    $efn = $extractedFile.Name
                    $f = [System.IO.File]::Open("$dir\$fileID\Extracted\$efn" ,"open","read","Read")
                    $sr = New-Object System.IO.StreamReader $f
                    $content = $sr.ReadToEnd()
                    $sr.close()
                    $f.close()                     
                     
                    if ($content.Contains($findstring))
                    {
                        Write-Host $templateUrl " :  " $extractedFile.Name -foreground green
                    }
                }               
            }
            $exportFile = $false
        }
    }
    $web.Dispose()

}

Tuesday, August 20, 2013

SharePoint 2013 migration issue with the SP.UI.ModalDialog error in javascript of CEWP

When there are javascript added to the Content Editor Web Part in SharePoint 2010, to open the dialog the code below is how you would do it but it breaks when you upgrade to 2013.

This works best if you add the new Script Webpart to the page and copy and paste all the scripts from the CEWP and leave the html as is.  

function openFormDialog(formtitle, formurl)
{
 var options = {
             url: formurl,
             tite: formtitle
         };

         SP.UI.ModalDialog.showModalDialog(options);
}

breaks in 2013

to fix the issue change the call to

function openFormDialog(formtitle, formurl)
{
 var options = {
             url: formurl + "?IsDlg=1",
             tite: formtitle
         };

SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

Wednesday, August 14, 2013

PowerShell Script to mount and Upgrade all site collections in a web application

Sometimes, the visual upgrade gets a bit buggy so use this instead and have no issues. Make sure you export all the solutions from the old central admin and add them and deploy them to the new Sharepoint 2013 environment. This way you will not have issues with the webparts and pages.

Add-PSSnapin Microsoft.SharePoint.Powershell
Mount-SPContentDatabase CSIHQ_Content -WebApplication http://server.com -AssignNewDatabaseId -DatabaseServer Dbservername
$SPwebApp = Get-SPWebApplication "http://server.com"
foreach ($SPsite in $SPwebApp.Sites) { Upgrade-SPSite $SPsite.Url -VersionUPGrade write-host $SPsite.url }