My app edits a file in SharePoint via Web Client/WebDAV(WebDAV redirector). How can I check out/check in?

StackOverflow https://stackoverflow.com/questions/537990

  •  22-08-2019
  •  | 
  •  

Question

I'm integrating my application so that it can edit files stored in SharePoint. I'm using the Web Client service AKA WebDAV Redirector(webclnt.dll) which does a wonderful job of letting the normal CreateFile/read/write Windows api calls be redirected from their normal drive I/O path out to the network via WebDAV. However, I can only get read-only access to the file if it's checked in.

Using the Web Client service, how can I cause the file to be checked out when I edit it, and then cause it to be checked in when I'm finished editing it?

Edit: I tried using the GetFileAttributes and SetFileAttributes to test for FILE_ATTRIBUTE_READONLY, hoping that I could use that flag to determine when the file was not checked out, and then to check it out (by unsetting that flag to check out, then setting it to check it in). No luck there; the file always appears as not read-only.

Was it helpful?

Solution

Well to perform check-in/check-out a file you need to use the following code:

SPSite oSite = new SPSite ("http://<sitename>/");
SPWeb oWeb = oSite.OpenWeb(); 
SPList oList = oWeb.Lists["Shared Documents"];
SPListItem oListItem = oList.Items[0]; //taking the first list item
oListItem.File.CheckOut();
oListItem["Name"] = "xyz";           
oListItem.Update();
oListItem.File.CheckIn("file name has been changed");

If you need to do check-in/check-out via the SharePoint WebService then you should take a look at the code on Brad McCable's blog on Windows Sharepoint Services Web Service Example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top