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

}

Monday, December 5, 2016

Find custom action or activity in a designer created 2010 workflow

While cleaning up my SharePoint farm for the cloud migration, i ran into an interesting problem.   If there are custom activity or action created for your designer workflow, how do you track down which ones uses those custom action or activity.

Here is a simple code to go through a site collection that returns all 2010 workflows that is using your custom action/activity that you created with code.

Add-PSSnapin *sharepoint* -ErrorAction SilentlyContinue

$encode = New-Object System.Text.ASCIIEncoding

$site = get-spsite "type in url"

foreach($w in $site.allwebs)
{
    foreach($wf in $w.Lists["workflows"].items)
    {
        if($wf.Name -like "*.xoml")
        {
            $file   = $wf.File
            $data   = $file.OpenBinary()
          
            $test   = $encode.GetString($data)
            if($test.Contains("text to find.  usually the namespace of the assembly of custom dll") -or $test.Contains("more text"))
            {
                  write-host $w.url $wf.Name
            }
        }
    }


Thursday, September 1, 2016

Report Builder: Unable to install this application

When you encounter an error trying to edit your report and the error states that you can not install the REPORTBUILDER:


/_vti_bin/ReportBuilder/ReportBuilder_3_0_0_0.application?ReportPath=


System.Deployment.Application.DeploymentException (Subscription)
  - Unable to install this application because an application with the same identity is already installed. To install this application, either modify the manifest version for this application or uninstall the preexisting application.
  - Source: System.Deployment
  - Stack trace:
   at System.Deployment.Application.SubscriptionStore.CheckApplicationPayload(CommitApplicationParams commitParams)
   at System.Deployment.Application.SubscriptionStore.CommitApplication(SubscriptionState& subState, CommitApplicationParams commitParams)
   at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
   at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
   at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)


---------------------------------------


Solution is to rather then change the config or manifest file.   Delete the Clickonce application files on your desktop or machine that you are working on located:


%userprofile%\AppData\Local\Apps\2.0\XXXXX.xxx\YYYYYYYY.YYY\*.*


Here is the example of the folders/files that you need to delete.  the command line is as follows:


del C:\Users\masteroftheUniverse\AppData\Local\Apps\2.0\TN076DJP.QJ2\TDNJXD8N.KQ1\*.*


then try to edit the report again, no issues.





Monday, June 13, 2016

Fix Designer error: Server-side activities have been updated. You need to restart SharePoint Designer to use the updated version of activities.

I have SharePoint Designer 2013 installed and working fine till I needed to install Visual Studio 2015 (I installed Enterprise but this error seems to occur with other versions).   So I researched the issue where some say, you have to un-install then re-install in particular order. 


Just run a repair on the SharePoint 2013 designer in control panel.   If you still get the error, then check the cache folder in your user profile and make sure you have the following files:


replace the <yourname> and <sitename> with your information below.


c:\Users\<yourname>\AppData\Local\Microsoft\WebsiteCache\<sitename>\versionnumber\


Microsoft.SharePoint.WorkflowServices.Activities.Proxy.dll
Microsoft.Web.Design.Client.dll



Tuesday, May 31, 2016

Upgrade MySite to SharePoint 2013 but the photos are not linking back

So I didn't want to follow the Microsoft recommended directions to upgrade mysite for upgrading the service applications for Metadata and the user profile service.   Which  was fine for the metadata service since they weren't using anything on it.   But the user profile service does present one issue, the photo, which is stored in the user profiles.  


But I do have all the pictures on the mysite since it is stored at the root web under the User Photos library.  


here is the script to update the user photos with powershell,   replace the TODO with your information:




[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$siteurl = "TODO fill in mysite url"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
write-host $site.RootWeb.Lists["User Photos"]
#Get list of photos
$list = $site.RootWeb.Lists["User Photos"]
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-host $list.Items.Count
foreach($listitem in $list.Items)
{
    if($listitem["Name"].ToString().Contains("LThumb") )
    {
      #  Write-host $listitem["Name"].ToString()
        $user = $listitem["Name"].ToString().Replace("_", "\").Substring(0, $listitem["Name"].ToString().LastIndexOf("_"))
    #    write-host $user
        $fullphotourl = $siteurl + "User%20Photos/Profile%20Pictures/" + $listitem["Name"].ToString();
        write-host $fullphotourl
        if ($upm.UserExists($user))
        {
            $profile = $upm.GetUserProfile($user)
            $profile["PictureURL"].Value = $fullphotourl;
            $profile.Commit();
        }
   
    }
}
$site.Dispose()

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, April 26, 2016

Upgrade from SharePoint 2013 to SharePoint 2016 issues

I created a new 2016 farm in another domain (development) so that i can test the upgrade from a 2013 farm.  The content upgrade is nice and simple as stated in all the blogs and documentation from microsoft.

Here is the big issue:   Workflow farm!

The 2010 workflows work fine since it is included with the content database but with the workflow farm introduced in 2013, there are multiple parts that needs to be there for it to work like the Application management service which gives the permissions for the workflow by the realms.  

Since the upgrade for 2016 service applications does not include the Application management, i'm stuck.  Here are the things i tried so far

  • follow the disaster recovery instructions with minor tweeks for WF pointing to the correct service bus, no go.
  • try to copy the activities to the new farm, no go.
  • try to re-publish the 2013 workflow in a new workflow farm, no go.  
  • possible thoughts but this will not work either due to the app management service, which was to share or use the same workflow farm from the 2013 sharepoint farm and the 2016 sharepoint farm.   


Here is another issue to consider, while doing the 2010 farm to 2013 upgrade, i could upgrade one web application at a time with no issues.   But with the 2013 to 2016 upgrade, i can not do this since the workflow farm holds all the 2013 farms web applications workflows in the same database (WFResourceManagementDB).  This causes some issues since if there is a simple fix for the first issue above then all the web applications need to be upgraded or the 2013 farm needs to point to the 2016 workflow farm.

Will update as i find the solution(s) to the issues found so far.   

Tuesday, April 5, 2016

Powershell script to generate powershell script to toggle publish feature

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$url = {your url here}
$site = get-spsite $url
$feature = $site.features.Item('f6924d36-2fa8-4f0b-b16d-06b7250180fa')
        
    if($feature -ne $null)
       {
            $ConfirmPreference = 'None'
       #     $feature
       #     Write-Host Disable-SPFeature -Identity $feature.DefinitionId -Url $site.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $site.Url  -Force   -WarningAction SilentlyContinue
      
       }
foreach($w in $site.AllWebs)
{
  #  Write-Host '#--------------------------------------------------------------------------------------'
  #  $w.Url
    $feature = $w.features.Item('94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb')
        
    if($feature -ne $null)
       {
       $ConfirmPreference = 'None'
         #   $feature
         #  Write-Host  Disable-SPFeature -Identity $feature.DefinitionId -Url $w.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $w.Url  -Force   -WarningAction SilentlyContinue
      
       }

}

Friday, February 19, 2016

SharePoint 2013 workflow can't terminate using UI: Terminate using powershell

Had a strange situation where the workflow instance will not terminate using the UI.   When I click on the status, it just gave an error so after tracking down what the error was in the uls which didn't give too much information but that something was a null where a value was expected: 


Getting Error Message for Exception System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentNullException: Value cannot be null.


at Microsoft.SharePoint.Workflow.SPWorkflow.retrieveSchema(Schema schemaIndex)


at Microsoft.SharePoint.Workflow.SPWorkflow.retrieveSchemaGuid(Schema schemaIndex)


at Microsoft.SharePoint.Workflow.SPWorkflow.get_AssociationId()


at Microsoft.SharePoint.Workflow.SPWorkflow.GetReadOnlyParentAssociation()


at Microsoft.SharePoint.Workflow.SPWorkflow.get_ParentAssociation()
.......




Here is the powershell to terminate the workflow instance that is suspended.  a slightly modified script from http://social.technet.microsoft.com/wiki/contents/articles/23850.sharepoint-2013-workflow-management-starting-a-workflow-using-powershell.aspx






Add-PSSnapin *sharepoint* -ErrorAction SilentlyContinue


$sourceWebURL = '<url to your web>'
$sourceListName = '<list name>'
$TargetWorkflow = '<workflow name>'
$itemId = <Id of the item the workflow you want to stop>


$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]

#-- Getting a Workflow manager object to work with.
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
#-- Getting a Workflow instance in order to perform my commands.
$wfis=$wfm.GetWorkflowInstanceService()


$wfinstances = $wfis.EnumerateInstancesForListItem($spSourceList.ID, $itemId)
foreach($wfi in $wfinstances)
{
    if($wfi.Status -eq "Suspended")
    {
        $wfi
        $wfis.TerminateWorkflow($wfi)
    }
}

Tuesday, February 2, 2016

SharePoint 2013 Usage service trouble shooting

Recently my farm encountered an issue with the Usage statistics not showing up in my reports but the data was still getting captured in the database.  


first thing to check are some status for your service application


$app = Get-SPServiceApplication -Identity '{Your usage service app guid}'


the get the usageapplication for some properties and status:


$ua = Get-SPUsageApplication -Identity $app


$ua.Status




if everything looks good, then make sure your usage definitions have Receivers:


$aud = Get-SPUsageDefinition | where {$_.Name -like "Analytics*"}


$aud | fl


$prud = Get-SPUsageDefinition | where {$_.Name -like "Page Requests"}


$prud | fl




Look at your results to make sure you have the following
-------------
EnableReceivers : True

Receivers : {Microsoft.Office.Server.Search.Analytics.Internal.AnalyticsCustomRequestUsageReceiver}





EnableReceivers : True

Receivers : {Microsoft.Office.Server.Search.Analytics.Internal.ViewRequestUsageReceiver}






finally if that's all good then unprovision your usage app and then go provision using Central admin:


first to unprovision:


$app = Get-SPServiceApplication -Identity '{Your usage service app guid}'
$app.Unprovision()


then in Central Admin, Monitoring, Configure usage and health data collection
-enable
-check items you want collected
-database name
-windows auth
-Ok


-----------------------------------------------------------------------------------------------------------------
Some very helpful links:


http://blogs.msdn.com/b/sharepoint_strategery/archive/2015/04/15/sp2013-search-index-health-reports-for-monitoring-and-troubleshooting.aspx




https://gallery.technet.microsoft.com/scriptcenter/Builds-SP-Search-2013-10d72a25


https://gallery.technet.microsoft.com/scriptcenter/Get-SPSearchTopologyState-b7452c6a