I have this code courtesy of Alex Angas in Programmatically instantiate a web part page in Sharepoint. I already posted this question on stackoverflow but didn't get any answer so I decided to transfer my question here.
In my _catalogs/masterpage folder, I have 2 masterpages namely:
- default.master
- mobilepage.master
I wanted to modify the code below in such a way that I could set the masterpage instead of default.master, I will make it to mobilepage.master which is created specifically for Mobile.aspx
This code below creates a mobile.aspx file inside the document library. My only problem is how to specify the masterpage of the mobile.aspx?
string newFilename = "Mobile.aspx";
string templateFilename = "spstd1.aspx";
string hive = SPUtility.GetGenericSetupPath("TEMPLATE\\1033\\STS\\DOCTEMP\\SMARTPGS\\");
FileStream stream = new FileStream(hive + templateFilename, FileMode.Open);
using (SPSite site = new SPSite("http://sharepoint")){
using (SPWeb web = site.OpenWeb())
{
SPFolder libraryFolder = web.GetFolder("Document Library");
SPFileCollection files = libraryFolder.Files;
SPFile newFile = files.Add(newFilename, stream);
}}
Please help me modify the code above. I would gladly appreciate your help. Thanks!