views:

870

answers:

1

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.

+1  A: 

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.

AboutDev
Thanks. I'll go this route if I can't find a file I/O method. My environment is C/C++ (unmanaged). Do you know of any examples using C/C++? I downloaded the SharePoint SDK, and it didn't contain any c/c++ samples. I haven't found any .h files that contain these classes either.
Steve
I haven't seen C++ code for SharePoint yet but I'm not developing in C++ for SharePoint either. I think you can try calling C# code from your C++ code or you can try access the Web Service that SharePoint provides through C++ (see the link to Brad McCable's blog in my answer). Good luck.
AboutDev