void CreateDocLib()
{
SPWeb _web = new SPSite("http://ianzhang/docs").OpenWeb();
//允许不安全的更新
_web.AllowUnsafeUpdates = true;
_web.AllowUnsafeUpdates = true;
//添加Demo文档库
_web.Lists.Add("Demo3", "Demo", SPListTemplateType.DocumentLibrary);
this.Label1.Text = _web.Lists["Demo3"].ID.ToString();
}
错语信息:
安全性异常
说明: 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。
异常详细信息: System.Security.SecurityException: 请求“Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”类型的权限已失败。
源错误:
行 33: this.Label1.Text = _web.Lists["Demo3"].ID.ToString(); 行 34: } 行 35: 行 36: static string GetViewXml() 行 37: { |
产生该问题的主要原因是moss的默认安全级别不允许第三方去操作 解决办法:修改sharepoint目录下的web.config文件(默认安装路径为C:/Inetpub/wwwroot/wss/VirtualDirectories/80) 将其中的<trust level="WSS_Minimal" originUrl="" /> 修改为<trust level="Full" originUrl="" />即可。 如果没有修改这个配置,则使用SPCAMLEditor1.1工具时,也无法正常使用。