【发布时间】:2011-09-15 11:00:49
【问题描述】:
我实际上是在创建一个 webpart 页面并使用来自 亚历克斯·安加斯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;
}
}
}
});
我遇到了这个错误
IOException 未被用户代码处理
进程无法访问文件'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\spstsd1.aspx'
但让我恼火的是,当我在调试模式下进入它时,错误不会出现。当我重新启动应用程序并在不踩到它的情况下运行它时,就会出现错误。有人可以帮我解决这个问题吗?
【问题讨论】:
标签: c# sharepoint sharepoint-2007