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

%3CLINGO-SUB%20id%3D%22lingo-sub-1407597%22%20slang%3D%22en-US%22%3EUnable%20to%20recreates%20editform.aspx%20of%20a%20sharepoint%20online%20library%20using%20PowerShell%20getting%20the%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1407597%22%20slang%3D%22en-US%22%3E%3CP%3EEdit%20Form%20is%20not%20present%20in%20the%20sharepoint%20online%20library.Due%20to%20threshold%20limit%20exceeded%20we%20are%20unable%20to%20recreate%20edit%20form%20using%20sharepoint%20designer%20so%20i%20am%20trying%20to%20recreate%20the%20edit%20form%20in%20sharepoint%20online%20using%20power%20shell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EAdd-Type%20-Path%20'C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CSharePointPnPPowerShellOnline%5C3.11.1907.0%5CMicrosoft.SharePoint.Client.dll'%20%0AAdd-Type%20-Path%20'C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CSharePointPnPPowerShellOnline%5C3.11.1907.0%5CMicrosoft.SharePoint.Client.Runtime.dll'%0A%20%0A%23Set%20parameter%20values%0A%24SiteURL%3D%22%22%0A%24listname%3D%22Editrecreate%22%0A%0A%23Setup%20Credentials%20to%20connect%0A%24Cred%3D%20Get-Credential%0A%24Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24Cred.Username%2C%20%24Cred.Password)%0A%0A%23Setup%20the%20context%0A%24Ctx%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%0A%24Ctx.Credentials%20%3D%20%24Credentials%0A%24Web%20%3D%20%24Ctx.Web%0A%24Ctx.Load(%24web)%0A%24Ctx.executeQuery()%0A%0Ado%7B%0A%0A%24list%20%3D%20%24Ctx.Web.Lists.GetByTitle(%24listname)%0A%24Ctx.Load(%24list)%0A%24Ctx.Load(%24list.rootfolder)%0A%24Ctx.ExecuteQuery()%0A%24files%20%3D%20%24list.rootfolder.files%0A%24Ctx.Load(%24files)%0A%24Ctx.ExecuteQuery()%0A%0A%26lt%3B%23----------------------------%20Delete%20Forms%20----------------------%0A%0A%24form1%20%3D%20%24list.RootFolder.files%20%7C%20%3F%7B%24_.url%20-match%20%22dispform.aspx%22%7D%0A%0A%24form2%20%3D%20%24list.RootFolder.files%20%7C%20%3F%7B%24_.url%20-match%20%22editform.aspx%22%7D%0A%0A%24form3%20%3D%20%24list.RootFolder.files%20%7C%20%3F%7B%24_.url%20-match%20%22newform.aspx%22%7D%0A%0A%24form2.delete()%0A%24form1.delete()%0A%24form3.delete()%0A%0A%24list.update()%23%26gt%3B%0A%0A%23%20--------------------------recreating%20--------------------------------%0A%0A%24editformurl%20%3D%20%24list.RootFolder.ServerRelativeUrl%20%2B%20%22%2Feditform.aspx%22%0A%23%24dispformurl%20%3D%20%24list.RootFolder.ServerRelativeUrl%20%2B%20%22%2FDispform.aspx%22%0A%23%24newformurl%20%3D%20%24list.RootFolder.ServerRelativeUrl%20%2B%20%22%2FNewForm.aspx%22%0A%24Ctx.Load(%24editformurl)%0A%24Ctx.ExecuteQuery()%0A%23%23%24dispform%20%3D%20%24files.add(%24dispformurl%2C%20%5BMicrosoft.SharePoint.SPTemplateFileType%5D%3A%3AFormPage)%0A%24editform%20%3D%20%24files.add(%24editformurl%2C%20%5BMicrosoft.SharePoint.SPTemplateFileType%5D%3A%3AFormPage)%0A%23%24newform%20%3D%20%24files.add(%24newformurl%2C%20%5BMicrosoft.SharePoint.SPTemplateFileType%5D%3A%3AFormPage)%0A%0A%24wpm%20%3D%20%24editform.GetLimitedWebPartManager(%5BSystem.Web.UI.WebControls.WebParts.PersonalizationScope%5D%3A%3AShared)%0A%23%24wpm2%20%3D%20%24dispform.GetLimitedWebPartManager(%5BSystem.Web.UI.WebControls.WebParts.PersonalizationScope%5D%3A%3AShared)%0A%23%24wpm3%20%3D%20%24newform.GetLimitedWebPartManager(%5BSystem.Web.UI.WebControls.WebParts.PersonalizationScope%5D%3A%3AShared)%0A%0A%24lfw1%20%3D%20new-object%20(%5BMicrosoft.SharePoint.WebPartPages.ListFormwebpart%5D)%0A%23%24lfw2%20%3D%20new-object%20(%5BMicrosoft.SharePoint.WebPartPages.ListFormwebpart%5D)%0A%23%24lfw3%20%3D%20new-object%20(%5BMicrosoft.SharePoint.WebPartPages.ListFormwebpart%5D)%0A%0A%24ilist1%20%3D%20%5BMicrosoft.SharePoint.WebPartPages.IListWebPart%5D(%24lfw1)%0A%23%24ilist2%20%3D%20%5BMicrosoft.SharePoint.WebPartPages.IListWebPart%5D(%24lfw2)%0A%23%24ilist3%20%3D%20%5BMicrosoft.SharePoint.WebPartPages.IListWebPart%5D(%24lfw3)%0A%0A%24ilist1.ListId%20%3D%20%24list.id%0A%24ilist1.PageType%20%3D%20%5BMicrosoft.SharePoint.PAGETYPE%5D%3A%3APAGE_EDITFORM%3B%0A%0A%23%24ilist2.ListId%20%3D%20%24list.id%0A%23%24ilist2.PageType%20%3D%20%5BMicrosoft.SharePoint.PAGETYPE%5D%3A%3APAGE_DISPLAYFORM%3B%0A%0A%23%24ilist3.ListId%20%3D%20%24list.id%0A%23%24ilist3.PageType%20%3D%20%5BMicrosoft.SharePoint.PAGETYPE%5D%3A%3APAGE_NEWFORM%3B%0A%0A%24wpm.AddWebPart(%24lfw1%2C%20%22Main%22%2C%201)%0A%23%24wpm2.AddWebPart(%24lfw2%2C%20%22Main%22%2C%201)%20%0A%23%24wpm3.AddWebPart(%24lfw3%2C%20%22Main%22%2C%201)%0A%0A%0A%23%24list.DefaultDisplayFormUrl%20%3D%20%24dispformurl%0A%24list.DefaultEditFormUrl%20%3D%20%24editformurl%20%0A%23%24list.DefaultNewFormUrl%20%3D%20%24newformurl%0A%0A%24list.update()%0A%7D%0Awhile%20(%24TRUE)%20%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CSTRONG%3EError%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%3CP%3Ewe%20are%20getting%20the%20below%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%20Unable%20to%20find%20type%20%5BMicrosoft.SharePoint.SPTemplateFileType%5D.%0AAt%20D%3A%5CPowerShellScripts%5CformsRecreate.ps1%3A55%20char%3A38%0A%2B%20...%20s.add(%24editformurl%2C%20%5BMicrosoft.SharePoint.SPTemplateFileType%5D%3A%3AFormPa%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20InvalidOperation%3A%20(Microsoft.SharePoint.SPTemplateFileType%3ATypeName)%20%5B%5D%2C%20RuntimeException%0A%20%20%20%20%2B%20FullyQualifiedErrorId%20%3A%20TypeNotFound%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BPlease%20help%20anyone%20thanks%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Visitor

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