Showing posts with label Infopath. Show all posts
Showing posts with label Infopath. Show all posts

Monday, January 28, 2019

Powershell to replace string in infopath in SharePoint Document library

So here is a simple/dirty script to update the files in your document library.  this particular script is for infopath documents with the template pointing to the wrong url after a migration

Add-PSSnapin *sharepoint* -EA SilentlyContinue

$web = Get-SpWeb https://url

#find your list (your call on what method to use
$list = $web.Lists[0] 

$oldstring = "https://url/libraryname/Forms/template.xsn"

$newstring = "https://url/Newlibraryname/Forms/template.xsn"

foreach($i in $list.Items)
{
  if($i.Title.Contains('.xml'))
  {
     $data = [System.Text.Encoding]::ASCII.GetString($i.File.OpenBinary())
     if($data.Contains($oldstring)
     {
         $data = $data.Replace($oldstring, $newstring)
       
          $i.File.SaveBinary([System.Text.Encoding]::ASCII.GetBytes($data))
      }
  }

}

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, May 31, 2016

Infopath template update does not complete apply when the document has digital signature

Encountered a strange issue where the form library template does not get fully applied with the changes when the document is signed using the browser.   If you open the form using the client, the templates gets applied and everything is kosher.


So tried all the basic things to get the browser form to upgrade or relink the form with the update template but no go.


Only one thing would work so, I had to write a little powershell script to open the forms with the InfoPath filler and submit it so that the form is saved with the template updates.




if the file is bigger than 50 MBs, you have to change the setting on the client machine.  it is defaulted to 50MB but you have files that are bigger so the registry setting has to be changed to increase the FileSizeLimitInBytes value located at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WebClient\Parameters]

find the TODO and replace with your own value
--------------------------------------------------------

Import-Module "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -AssemblyName Microsoft.Office.Interop.InfoPath
#url
$site = "TODO:  url of the site"
#user name
$admin = "TODO: account name with domain.  I used user@domain"
#Get Password as secure String
$password = Read-Host "Enter Password" -AsSecureString
#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
#Authenticate
$credentials = New-Object System.Net.NetworkCredential($admin , $password)
$context.Credentials = $credentials
write-host "authenicated"
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
write-host $web.Title

$list = $context.Web.Lists.GetByTitle("TODO: ListName to be filled in")


#write-host $list.Title
$context.Load($list)
$context.ExecuteQuery()
write-host $list.Title
write-host $list.

$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(1000, "Title");
$items = $list.GetItems($query);
$context.Load($items);
$context.ExecuteQuery();

 #$context.Url
write-host $items.Count
$iApp = New-Object  Microsoft.Office.Interop.InfoPath.ApplicationClass
#$sdoc = New-Objct Microsoft.Office.Interop.InfoPath.XDocumentClass
$versionMode = New-Object Microsoft.Office.Interop.InfoPath.XdDocumentVersionMode
foreach($li in $items)
{
    #write-host  $li["Title"].ToString()
   
    $url = "TODO: Url of the list" + $li["Title"].ToString()
  
   #write-host $url
   try
   {
    $xdoc = $iApp.XDocuments.Open($url) #, $versionMode.xdCanTransformSigned)
        $xdoc.Save()
            $xdoc.CloseDocument()
             write-host  "Done 1:  "  $li["Title"].ToString()
    }
    catch
    {
        try
        {
            $xdoc = $iApp.XDocuments.Open($url, 18)  # 16 for $versionMode.xdCanTransformSigned + 2 for xdUseExistingVersion)
             $xdoc.Save()
            $xdoc.CloseDocument()
             write-host  "Done 2:  "  $li["Title"].ToString()
        }
        catch {
            $ErrorMessage = $_.Exception.Message
          
             write-host  "ERROR:  " $ErrorMessage " ::: " $li["Title"].ToString()
        }
    }
   
   
}

$context.Dispose()

Tuesday, September 9, 2014

SharePoint Error in people picker in Infopath filler for SSL termination at F5 rather than at the web application/IIS level

The error occurs in the InfoPath filler people picker:  calls fails /_vti_bin/spclaimproviderwebservice.https.svc


when the SSL termination is done at the F5. 


To resolve, you'll need to create a iRule in F5 or in IIS to strip of the .https for the following two services:


spclaimproviderwebservice.https.svc
and
cellstorage.https.svc

IIS:

<rule name="SpClaimProviderWebService" stopProcessing="true">
<match url="^(.*)spclaimproviderwebservice.https.svc$" />
<action type="Rewrite" url="{R:1}spclaimproviderwebservice.svc" />
</rule>


<rule name="cellStorage" stopProcessing="true">
<match url="^(.*)cellstorage.https.svc$" />
<action type="Rewrite" url="{R:1}cellstorage.https.svc" />
</rule>


F5:


when HTTP_REQUEST {
if { [[string tolower] [HTTP::path]] contains "spclaimproviderwebservice.https.svc"} {
HTTP::path [string map {.https ""} [HTTP::path]]
}
}
when HTTP_REQUEST {
if { [[string tolower] [HTTP::path]] contains "cellstorage.https.svc"} {
HTTP::path [string map {.https ""} [HTTP::path]]
}
}

Tuesday, September 2, 2014

SharePoint 2013 Infopath browser form, people picker error in IE 11: JSON is undefined

This is a strange compatibility issue so have a ticket open with Microsoft so will update with the real fix (i'm assuming that it will be a hot fix).

When you open a people picker in IE 11 for a infopath form in the browser, the error get's thrown, JSON is undefined.

the temporary fix is to add teh following to the pickerdialog.master in the layouts folder.

Add this to the top of the page:
<!DOCTYPE html>


Replace the meta tag where it has
<meta http-equiv="X-UA-Compatible" content="IE=10" />

with the following:

 <meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" />
<!--[if lt IE 9]>
 <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
 <script src="http://code.jquery.com/jquery-2.0.3.js"></script>
<!--<![endif]-->

Save.

Test your people picker on infopath browser form.

Friday, December 23, 2011

Performance issues with Infopath and Sharepoint Lists

In a data connection, if you check "Automatically retrieve data when the form is opened",  make sure that it is not a large list.  The underlying query pulls all the items from that list.  Also this option is checked by default. 

Even if this connection might be used to insert an item in a list, it will still pull the data and can cause performance issues of taking a bit of time to load the form.