I have an existing sharepoint list generated by the sharepoint UI. I want to add a custom NewForm to this list that uses its own code behind, because I need to do a lot of stuff in the logic. As far as I have seen, it is not possible to manipulate the code behind of forms via Sharepoint Designer, so I´d rather reference a form created with Visual Studio in the list. 

My problem is that the list already exists and that I don´t know how to dock a custom visual studio form to it. If I could create the list from scratch in VS everything would be fine.

**Edit**

I followed a [post](http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2b3e9ea0-4841-4387-ac62-e431078a2570/how-to-create-a-custom-form-for-sharepoint-list-through-vs-2010) and deployed the form to the SP layouts folder. Along with it I deployed a feature and in the activated event receiver used the following code:

```
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPSite site = SPContext.Current.Site;
    using (SPWeb web = site.OpenWeb("mysite"))
    {

       SPList lstTest = web.Lists["MyList"];

       string newUrl = string.Format("{0}/{1}/layouts/NewForm.aspx", web.ServerRelativeUrl, lstTest.RootFolder.Url);

       var form = web.GetFile(newUrl);

       if (form != null && form.Exists)

       {
           lstTest.DefaultNewFormUrl = newUrl;
           lstTest.Update();
       }
    }
}

```

This did not work because form.Exists is false. If removed, I get the following error:

> 
> Unable to find an SPForm matching URL /mysite/Lists/MyList/layouts/NewForm.aspx.
>  Parameter name: url 
> 
> 
>