Checkin/Checkout documents, Sharepoint, Web services

Well you are going to have to be more specific in what you are trying to accomplish. The web service will only be able to checkin/checkout files that are checked out to the user calling the web service. You need to call GetListItems with a caml query for all the checked out items to the current user. Then take the returned xml and grab all the FileRef attributes. Then you can call CheckInFile on each one.  The code below will take the user's login name and query for any checked out documents. It returns the xmlNode and using xml linq extracts the FileRef attributes. It then takes the substring of the FileRef and appends the server name calling the UpdateListItemCheckInFile method wth the complete url to the document. You can the example code to pull document's based on whatever criteria you want and use the same technique to check out documents.

public static void CheckInAllMyCheckedOutDocuments()

{

            string query = "<mylistitemrequest><Query><Where><Eq><FieldRef Name=\"CheckoutUser\" /><Value Type=\"User\">basesmcdev2\\steve.curran</Value></Eq></Where><OrderBy><FieldRef Name=\"Title\"/></OrderBy></Query><ViewFields><FieldRef Name=\"Title\"/></ViewFields><QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions></mylistitemrequest>";



            XmlDocument doc = new XmlDocument();

            doc.LoadXml(query);





            listservice.Lists listProxy = new listservice.Lists();



            listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";

            listProxy.UseDefaultCredentials = true;



            XmlNode queryNode = doc.SelectSingleNode("//Query");

            XmlNode viewNode = doc.SelectSingleNode("//ViewFields");

            XmlNode optionNode = doc.SelectSingleNode("//QueryOptions");





            try

            {

                XmlNode retNode = listProxy.GetListItems("tester2", null, queryNode, viewNode, string.Empty, optionNode, null);



                XElement e = XElement.Parse(retNode.InnerXml);

                var uniqueValues = (from t in e.Descendants().Attributes("ows_FileRef") select t.Value.ToString()).Distinct();



                foreach (string fileRef in uniqueValues)

                {

                    UpdateListItemCheckIn("http://basesmcdev2/" + fileRef.Substring(fileRef.IndexOf("#")+1));

                }







            }

            catch (Exception ex)

            {



                string msg = ex.Message;

            }





}





public static void UpdateListItemCheckIn(string fileRef)

{

            listservice.Lists listProxy = new listservice.Lists();





            listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";

            listProxy.UseDefaultCredentials = true;



            bool success = listProxy.CheckInFile(fileRef, string.Empty, "0");



}



你可能感兴趣的:(web services)