0

We have a list for which we wanted to bind a custom aspx page for editing the list item.

we have written the following sample console application to check it.

public class Program
{
    public static void Main(string[] args)
    {
        using (SPSite site = new SPSite("http://HostName/"))
        {
            using (SPWeb web = site.RootWeb) // Tried with site.openWeb() also
            {
                SPList discList = web.Lists["ListWithCustomEditForms"];

                SPFormCollection listForm = discList.Forms;
                foreach (SPForm form in listForm)
                {
                    Console.WriteLine(form.ServerRelativeUrl); 
                }

                discList.DefaultEditFormUrl = @"~/layouts/CustomList_DynamicEditForm/EditListItemTest.aspx";
                discList.Update();

                Console.WriteLine("Done!!!!");

            }
        }
        Console.ReadLine();
    }
}

it's not accepting any path. Always it's throwing exception saying "Unable to find an SPForm matching URL ....". I have tried multiple options. but nothing is working.

Anything wrong with my code or is there any way to set the custom edit form for a list item?

0

Their has to be a proper schema defined for creating your custom edit form.

I think you have missed some required attributed in your custom edit form.

0

We can't set the application (aspx) page located in the layouts folder as default NewFormUrl. This property is only supports the form within the List Folder or within SPFormCollection of the List.

What you need to use is a content type. You can set the new,edit,display formurls within the specific Content Type and use that content type within the list.

                    web.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["My List"];
                    SPContentType ct = list.ContentTypes["Item"];
                    ct.NewFormUrl = "_layouts/newform.aspx";
                    ct.Update();
                    web.AllowUnsafeUpdates = false;

Note that the string of the url starts with the underscore. "_layouts...".

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.