Checkin/Checkout documents, Sharepoint, Web services

本文介绍了一种使用SharePoint Web服务批量检入当前用户已借出文档的方法。通过构造特定的CAML查询,获取所有当前用户已借出的项目,并通过XML LINQ解析返回的XML以获取文件引用。然后遍历这些文件引用并调用UpdateListItemCheckInFile方法完成检入过程。

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");

}

转载于:https://www.cnblogs.com/ahjxxy/archive/2010/11/04/1869376.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值