1

Looking for C# code to find all document libraries and lists that have InfoPath enabled on them. Sites are 2010/2013 SharePoint sites.

0

You can write to console or save into file. It list all lists and libraries where is used Template with XSN:

asnp *sharepoint*
cls

#$ct = @()
$wa = get-spwebapplication https://sharepoint.dev.cz
$wa

foreach($site in $wa.sites)
{
    foreach($Web in $site.AllWebs)
    {
        foreach($list in $Web.Lists)
        {
            if($list.AllowContentTypes -eq $true)             
            {
                if(-not ($systemlibs -Contains $list.Title))
                {
                    if ($list.AllowContentTypes -eq $true)
                    {                           
                        foreach ($contenttype in $list.ContentTypes)
                        {
                            if($contenttype.DocumentTemplateUrl -like "*.xsn")
                            {
                                $ctObject = New-Object -TypeName PSObject
                                $ctObject | Add-Member -Name 'WebTitle' -MemberType Noteproperty -Value $web.Title
                                $ctObject | Add-Member -Name 'WebUrl' -MemberType Noteproperty -Value $web.URL
                                $ctObject | Add-Member -Name 'ListTitle' -MemberType Noteproperty -Value $list.Title                                
                                $ctObject | Add-Member -Name 'ContentType' -MemberType Noteproperty -Value $contenttype.Name   
                                $ctObject | Add-Member -Name 'ContentTypeUrl' -MemberType Noteproperty -Value $contenttype.DocumentTemplateUrl 
                                #$ct += $ctObject                      
                                Write-Host $ctObject
                            }
                        }                           
                    }
                }
            }
        }
    }
}

#$ct | export-csv "filename.csv"
  • This worked! Used this logic in C# CSOM code and works fine. Thanks! – Aswathi P Feb 8 at 10:08
  • Further, how can I get details of the info path form that is used? – Aswathi P Feb 8 at 12:11
  • What info you are expecting? – Zdeněk Vinduška Feb 8 at 12:32
  • Any identifier for the InfoPath form. Like name of the file or url. Scenario: I have a Library that uses multiple InfoPath forms. After migration need to see if they exist in the target SharePointt online site. So need to match the files. Currently trying to get the File using url and then filename. Works well so far. Open to other ideas – Aswathi P Feb 11 at 9:08
  • but with my code you have the name in the last column "ContentTypeUrl" there is something like "/library/TemplateName.xsn" that's name.If there are more templates, there will be listed more templates. – Zdeněk Vinduška Feb 11 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.