我试图删除页面中的所有内容。但是当我尝试这样做时,我得到一个例外,它说文件没有检出,我必须这样做。当我使用file.CheckOut()
时,我看到该文件被签出到systemAccount,我得到了异常:
该文件是CheckedOut给另一个用户
如何做到这一点我可以忽略当前/特定用户的CheckOut
这是我试过的
SPSecurity.RunWithElevatedPrivileges(delegate()
{
var webMngr = web.GetLimitedWebPartManager("Sidor/default.aspx", PersonalizationScope.Shared);
List<System.Web.UI.WebControls.WebParts.WebPart> webPartList = (from System.Web.UI.WebControls.WebParts.WebPart webPart in webMngr.WebParts select webPart).ToList();
SPFile file = web.GetFile(web.Url+"Sidor/default.aspx");
web.AllowUnsafeUpdates = true;
if (file.CheckOutType == SPFile.SPCheckOutType.Online)
{
file.CheckIn("Comment");
}
file.CheckOut();
object _lock = new object();
lock (_lock)
{
for (int i = 0; i < webMngr.WebParts.Count; i++)
{
webMngr.DeleteWebPart(webPartList[i]);
}
}
web.AllowUnsafeUpdates = false;
});
答案 0 :(得分:0)
file.forceCheckOut = false
这里是msdn函数 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.forcecheckout(v=office.15).aspx