I am facing some specific issue here regarding SharePoint Lists New/display/edit forms...
I explain:
I have created (from Visual studio) a SharePoint List based on DiscussionBoard ListTemplate. now i want to customize the NewForm and EditForm of that list.
I walked through several approches; for examlpe modifiying in the Schema.xml but this only works for custom Lists not for Sharepoint list (those who are based on Templates like Discussion board) because i have only the listInstanceFile and the elements.xml file i don't have the schema.xml file to make my modifications in it.
I tried then to do that programmatically, i tried the following (after creating an application page in a mapped layout folder)
string sDirectory=Microsoft.SharePoint.Utilities.SPUtility.GetCurrentGenericSetupPath(@"TEMPLATE\LAYOUTS\TetSPCustomForms");
string newUrl = sDirectory + @"\DiscussionApplicationPage.aspx";
var form = web.GetFile(newUrl);
if (form != null && form.Exists)
{
lstTest.DefaultNewFormUrl = newUrl;
lstTest.Update();
}
This doesn't work; The GetFile is getting out of range...
I tried also this,(after creating an application page and putting it under the list)
string urlNew = lstTest.DefaultNewFormUrl.Replace("NewForm.aspx", "D2appPage.aspx");
lstTest.Update();
I tried this after,
var web = properties.Feature.Parent as SPWeb;
if (web == null) return;
SPList lstTest = web.Lists["testBoard"];
string newUrl = string.Format("{0}{1}/D2appPage.aspx",web.ServerRelativeUrl,lstTest.RootFolder.Url);
newUrl is getting a wrong one ...
And lastly i tried this
SPList myList = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, "/Lists/testBoard")); //Rq var list = web.Lists.TryGetList("testBoard"); var rootFolder = list.RootFolder;
var newFormUrl = string.Format("{0}", list.DefaultNewFormUrl);
var newForm = web.GetFile(newFormUrl);
if (newForm != null && newForm.Exists)
newForm.Delete(); // delete & recreate our new form
newForm = rootFolder.Files.Add(newFormUrl, SPTemplateFileType.FormPage);
var wpm = newForm.GetLimitedWebPartManager(PersonalizationScope.Shared);
var webpart = new ListFormWebPart
{
ListId = list.ID,
ListName = list.ID.ToString("B").ToUpper(),
PageType = PAGETYPE.PAGE_NEWFORM,
Title = list.Title,
Description = list.Description,
CatalogIconImageUrl = list.ImageUrl,
TitleUrl = list.DefaultViewUrl,
//TemplateName = "SomeCustomRenderingTemplate"
};
wpm.AddWebPart(webpart, "Main", 0);
nothing is getting changed...
Am i missing something ?
Any help will be appreciated.