Sharepoint the file is locked for use domainuser edit.文件被锁定,解锁方式

Sharepoint 文档被短期锁定,锁定状态为Short-term,该方式无法通过文档Checkin(comments)进行嵌入。

造成该文档锁定的原因是用户打开了文件,Sharepoint默认会锁定一段时间(1小时),在这1小时内是不可以修改的。

如果要进行修改,必须解锁,网络上大多的做法就是修改服务器时间,或者等1小时。最后在一个英文博客上找到更快的解决方式。

通过连接数据库,修改被短期锁定的文档的签出/释放时间即可,方法如下:

private void UnlockedFileFromDB(SPListItem item)
        {
            SqlConnection con = null;
            try
            {
                con = new SqlConnection(item.Web.Site.ContentDatabase.DatabaseConnectionString);
                con.Open();
                string updateCommandText = string.Format("UPDATE dbo.AllDocs SET " +
                                                         "CheckoutExpires = '{0:yyyy-MM-dd HH:mm:ss:fff}' WHERE Id = '{1}'",
                                                          DateTime.Now.ToUniversalTime(), item.UniqueId.ToString());
                SqlCommand UpdateCommand = new SqlCommand(updateCommandText, con);
                SqlDataAdapter contentDataAdapter = new SqlDataAdapter();
                contentDataAdapter.UpdateCommand = UpdateCommand;
                contentDataAdapter.UpdateCommand.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (con != null && con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
            }
        }

方式二(2016/5/24更新):

if (nFile.CheckOutStatus == SPFile.SPCheckOutStatus.ShortTerm)
{
     nFile.ReleaseLock(nFile.LockId);
}

原文地址:https://www.cnblogs.com/zchblog/p/5508963.html