4

I have created the custom page named 'preview.aspx' in survey list by using SharePoint designer.and I have added some functionality to it.

I need to add this file to Sharepoint list form pages using c# (through web part code behind).also, In this process, I changed the list name and list id dynamically.It's not working.

it's working when we deploying without changing the list name. I am not sure about this I have tried the below code...

Currentweb.AllowUnsafeUpdates = true;
SPList list = Currentweb.Lists.TryGetList(surveyName);
string _listID = list.ID.ToString();
var path = SPUtility.GetVersionedGenericSetupPath(@"TEMPLATE\LAYOUTS\SurveyRefactoring\preview.aspx", 15);
var text = System.IO.File.ReadAllText(path);
FileCreationInformation();
string ListId = "ListId=\"" + _listID + "\"";

SPList list = web.Lists["Tasks"];
Guid defaultView = list.DefaultView.ID;
Guid otherView = list.Views["All Tasks"].ID;


text = text.Replace("ListId=\"c2e41257-aadf-4605-8e64-ecc51c7c8d90\"", ListId);

System.IO.File.WriteAllText(path, text);
FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);

SPFile newForms = list.RootFolder.Files.Add(list.ParentWeb.ServerRelativeUrl + "/" + list.RootFolder.Url + "/preview.txt", file);

It throwing an invalid file error message in the last line(Adding page in the list) Any help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.