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()

No comments:

Post a Comment