Fix “Unable to find the default edit form for list” programmatically without SharePoint Designer

Sometime you may meet an error when you add new item or edit item properties. A yellow screen is showing like below, or, a standard SharePoint error window popped up and said “Unable to find the default edit form for list (listname)”.


Mostly that is the edit form (or add item form) has been deleted. However, sometimes the form still there but it becomes blank page. The form can be access by the url /{your list}/Forms/EditForm.aspx


And you will find the DefaultEditFormUrl property of this list is empty. An error will occurred if you try to set this property to the existing form page via PowerShell. The error saying “Unable to find an SPForm matching URL”


All above is saying same thing: the data form web part in this form has been deleted.

The easiest way to fix this issue is use SharePoint Designer to fix the form or recreate a form. However, sometimes we cannot do that because the environment doesn’t allow SPD connection for some reason, mostly because security. We have to find another way.

Thanks two good posts SharePoint 2010 Create and Update List Forms Programmatically and SharePoint 2010 – Add custom list form to existing list, I created a PowerShell script to fix this issue without SharePoint designer.

$web = get-spweb yoursiteurl
$list = $web.Lists[yourlistname]
$rootFolder = $list.RootFolder;
$formFolder = $rootFolder.SubFolders["Forms"]
$editForm = $formFolder.Files["EditForm.aspx"]
$manager = $editForm.GetLimitedWebPartManager(1)

$newWebPart = new-Object Microsoft.SharePoint.WebPartPages.ListFormWebPart
$newWebPart.ListId = $list.ID
$newWebPart.ListName = $list.ID.ToString("B").ToUpper()

#set the page type. 6: Editform, 8: Newform, 4: Displayform
$newWebPart.PageType = 6
$newWebPart.Title = $list.Title
$newWebPart.Description = $list.Description
$newWebPart.CatalogIconImageUrl = $list.ImageUrl
$newWebPart.TitleUrl = $list.DefaultViewUrl

#this is very important that implement the web part with IListWebPart interface. If not do that the web part and form will not be identified by SP as an available form
[Microsoft.SharePoint.WebPartPages.IListWebPart]$part = $newWebPart

$manager.AddWebPart($part, "Main", 0)
$part.ShowToolbarWithRibbon = $true

$list.DefaultEditFormUrl = $web.ServerRelativeUrl + "/" + $rootFolder.Url + "/Forms/EditForm.aspx"

After run this script, your edit form is come back.


Enjoy it!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s