I have the following code, which I use to check out a file from my Document Library:

var ctx = new ClientContext("http://sharepoint/mysite");
var web = ctx.Web;
var file = web.GetFileByServerRelativeUrl("mysite/documentlibrary/filename.pdf");
file.CheckOut();
ctx.ExecuteQuery();

This code appears to work on most occasions, but sometimes when calling it I get this error message on the last line:

"The file 'http://sharepoint/mysite/documentlibrary/filename.pdf' is not checked out."

When I navigate to the file in a browser, I can see that the file is indeed not checked out, but the error is not helpful at all as that is what I am trying to do!

I am also unable to check the file out manually from the browser with the same message.

Does anyone know what might be happening here?

有帮助吗?

解决方案 2

To solve this I went into the file properties and selected Unpublish this version :

enter image description here

After doing this and then making sure the file was checked in, I was able to check it out manually as well as with the following code:

using (var ctx = new ClientContext(_sitename))
{
    var web = ctx.Web;
    var file = web.GetFileByServerRelativeUrl(serverRelativeUrl);
    ctx.Load(file);
    file.CheckOut();
    ctx.ExecuteQuery();
}

其他提示

Try this instead:

var ctx = new ClientContext("http://sharepoint/mysite");
var web = ctx.Web;
var file = web.GetFileByServerRelativeUrl("mysite/documentlibrary/filename.pdf");
ctx.Load(file);
ctx.ExecuteQuery();
file.CheckOut();
许可以下: CC-BY-SA归因
scroll top