Unable to recreates editform.aspx of a sharepoint online library using PowerShell getting the error

Copper Contributor

Edit Form is not present in the sharepoint online library.Due to threshold limit exceeded we are unable to recreate edit form using sharepoint designer so i am trying to recreate the edit form in sharepoint online using power shell.

 

 

Add-Type -Path 'C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.11.1907.0\Microsoft.SharePoint.Client.dll' 
Add-Type -Path 'C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.11.1907.0\Microsoft.SharePoint.Client.Runtime.dll'
 
#Set parameter values
$SiteURL=""
$listname="Editrecreate"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$Web = $Ctx.Web
$Ctx.Load($web)
$Ctx.executeQuery()

do{

$list = $Ctx.Web.Lists.GetByTitle($listname)
$Ctx.Load($list)
$Ctx.Load($list.rootfolder)
$Ctx.ExecuteQuery()
$files = $list.rootfolder.files
$Ctx.Load($files)
$Ctx.ExecuteQuery()

<#---------------------------- Delete Forms ----------------------

$form1 = $list.RootFolder.files | ?{$_.url -match "dispform.aspx"}

$form2 = $list.RootFolder.files | ?{$_.url -match "editform.aspx"}

$form3 = $list.RootFolder.files | ?{$_.url -match "newform.aspx"}

$form2.delete()
$form1.delete()
$form3.delete()

$list.update()#>

# --------------------------recreating --------------------------------

$editformurl = $list.RootFolder.ServerRelativeUrl + "/editform.aspx"
#$dispformurl = $list.RootFolder.ServerRelativeUrl + "/Dispform.aspx"
#$newformurl = $list.RootFolder.ServerRelativeUrl + "/NewForm.aspx"
$Ctx.Load($editformurl)
$Ctx.ExecuteQuery()
##$dispform = $files.add($dispformurl, [Microsoft.SharePoint.SPTemplateFileType]::FormPage)
$editform = $files.add($editformurl, [Microsoft.SharePoint.SPTemplateFileType]::FormPage)
#$newform = $files.add($newformurl, [Microsoft.SharePoint.SPTemplateFileType]::FormPage)

$wpm = $editform.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#$wpm2 = $dispform.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#$wpm3 = $newform.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$lfw1 = new-object ([Microsoft.SharePoint.WebPartPages.ListFormwebpart])
#$lfw2 = new-object ([Microsoft.SharePoint.WebPartPages.ListFormwebpart])
#$lfw3 = new-object ([Microsoft.SharePoint.WebPartPages.ListFormwebpart])

$ilist1 = [Microsoft.SharePoint.WebPartPages.IListWebPart]($lfw1)
#$ilist2 = [Microsoft.SharePoint.WebPartPages.IListWebPart]($lfw2)
#$ilist3 = [Microsoft.SharePoint.WebPartPages.IListWebPart]($lfw3)

$ilist1.ListId = $list.id
$ilist1.PageType = [Microsoft.SharePoint.PAGETYPE]::PAGE_EDITFORM;

#$ilist2.ListId = $list.id
#$ilist2.PageType = [Microsoft.SharePoint.PAGETYPE]::PAGE_DISPLAYFORM;

#$ilist3.ListId = $list.id
#$ilist3.PageType = [Microsoft.SharePoint.PAGETYPE]::PAGE_NEWFORM;

$wpm.AddWebPart($lfw1, "Main", 1)
#$wpm2.AddWebPart($lfw2, "Main", 1) 
#$wpm3.AddWebPart($lfw3, "Main", 1)


#$list.DefaultDisplayFormUrl = $dispformurl
$list.DefaultEditFormUrl = $editformurl 
#$list.DefaultNewFormUrl = $newformurl

$list.update()
}
while ($TRUE)  

 

 

 

Error

we are getting the below error.

 

 

 

 Unable to find type [Microsoft.SharePoint.SPTemplateFileType].
At D:\PowerShellScripts\formsRecreate.ps1:55 char:38
+ ... s.add($editformurl, [Microsoft.SharePoint.SPTemplateFileType]::FormPa ...
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.SharePoint.SPTemplateFileType:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

 

 

 Please help anyone thanks in advance.

0 Replies