我想从文档库中读取一个项目,然后删除它。我遇到安全异常的问题:“此页面的安全验证无效”
我做错了什么?我正在使用Elevated Privilages执行命令!
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSiteCollection = new SPSite(SharePointInfo.SubSiteUrl))
{
using (SPWeb oWebsite = oSiteCollection.OpenWeb())
{
SPList uploadFilesLibrary = oWebsite.Lists[SharePointInfo.UploadFilesLibraryName];
if (files.Count > 0)
{
foreach (var fileToSend in files)
{
try{
/*SPFile file = uploadFilesLibrary.Items.Cast<SPListItem>()
.Where(x => x.Name.Equals(fileToSend))
.Select(x => x.File).First();*/
SPListItem p = uploadFilesLibrary.Items.Cast<SPListItem>()
.Where(x => x.Name.Equals(fileToSend)).First();
byte[] binaryFile = p.File.OpenBinary();
p.Delete();
aux = new FileAttachesForm(fileToSend, System.Convert.ToBase64String(binaryFile));
rtn.Add(aux);
}catch (Exception ex){
string errMessage = string.Format("Error al descargar el fichero desde SP: {0} - Pila: {1}", ex.Message, ex.StackTrace);
Logger.LogError(errMessage, ex);
throw ex;
}
}
}
}
}
});
return rtn;
}
答案 0 :(得分:0)
尝试在if
内添加此内容:
oSiteCollection.AllowUnsafeUpdates = true;
看看这个相关的问题: