1

There are couple of custom content types under a content type group. These content types are added to a SP Library. The ribbon in the library lets user select a content type in the library.

The requirement is to associate each content type with a edit form so that when user selects the content type in the ribbon, the related edit form is displayed to enter meta data which will be saved to the library later on. So can a application page be associated to a content type? Each content type will have its own edit form(in this case an Application page)

Basically the idea is to have a edit form per content type to save the meta-data regardless of the library/list

1 Answer 1

0

Yes you can have custom forms for content types. You need to set properties for the content type, and this can be done in various ways. Below is the PowerShell function which will do the job.

I have not fully tested the code, but I think this can be helpful

    function SetCustomForms-InContentType()
    {
        param(
            [Parameter(Mandatory=$true)][string]$url,
            [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
            [Parameter(Mandatory=$true)][string]$ContentTypeName
        )

        begin{
            try
            {
                #get Client Object
                $Context = New-Object Microsoft.SharePoint.Client.ClientContext($url) 
                $Context.Credentials = $Credentials 

                #Load web object
                $web = $Context.Web
                $site = $context.Site 
                $Context.Load($web)
                $Context.Load($site)
                $Context.ExecuteQuery()

            }
            catch
            {
                Write-Host "Error while getting context. Error -->> "  + $_.Exception.Message -ForegroundColor Red
            }
        }
        process{
            try
            {

                $contentTypes = $Context.Site.RootWeb.ContentTypes
                $Context.Load($contentTypes)
                $Context.ExecuteQuery()
                $contentType = $contentTypes | Where {$_.Name -eq $ContentTypeName}

                $contentType.EditFormUrl = "Your Custom URL"
                $contentType.NewFormUrl = "Your Custom URL"
                $contentType.DisplayFormUrl = "Your Custom URL"


                $contentType.Update()
                $Context.Load($contentType)
                $Context.ExecuteQuery()
            }
            catch
            {
                Write-Host ("Error -->> " + $_.Exception.Message) -ForegroundColor Red
            }
        }
        end{
            $Context.Dispose()
        }
    }


    $credentials = Get-Credential
    $Url = 'http://YourSite'

    SetCustomForms-InContentType $Url $credentials "Your Content Type Name" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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