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

}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值