I'm actually creating a webpart page and use this technique from the post of Alex Angas in Programmatically instantiate a web part page in Sharepoint
string SiteLocation = "http://abcd.com/sites/forum/";
SPSecurity.RunWithElevatedPrivileges(delegate(){
using(SPSite site = new SPSite(SiteLocation)){
using(SPWeb web = site.OpenWeb()){
foreach(SPWeb oweb in web.Webs){
bool allowUnsafeUpdates = oWeb.AllowUnsafeUpdates;
oWeb.AllowUnsafeUpdates = true;
string strFileName = "Mobile.aspx";
string strTemplateFileName = "spstd1.aspx";
string strPath = "TEMPLATE\\1033\\STS\\DOCTEMP\\SMARTPGS";
string hive = SPUtility.GetGenericSetupPath(strPath);
//--- Error encountered on this line ---
FileStream stream = new FileStream(hive + strTemplateFileName,FileMode.Open);
//--------------------------------------
SPFolder libraryFolder = oWeb.GetFolder(WebPartPageDocLibName);
SPFileCollection files = libraryFolder.Files;
SPFile newFile = files.Add(strFileName, stream);
oWeb.Update();
oWeb.AllowUnsafeUpdates = allowUnsafeUpdates;
}
}
}
});
I encounter this error
IOException was unhandled by user code
The process cannot access the file 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\spstsd1.aspx'
but what irritates me is that when I step into it in debugging mode, the error won't appear. And when I restart the application and run it without stepping on to it, the error comes out. Can someone help me on this please.