Update ListItems and Check-In file in Moss 2007 using Web Services


In my project I'm facing one typical situation, while download the file few of the files are Checked out status, we can't download the file if the status is in Check-out, so I thought to Check-In files before download it, but it's not possible to check-In bulk of files with in fraction of seconds, So I decided to Check-In all the files through code.

Update ListItems and Check-In file in Moss 2007 using Web Services:




Index:



1. Description
2. Web Service Methods
3. Source Code
4. Output
5. Conclusion

1. Description:



In my project I'm facing one typical situation, while download the file few of the files are Checked out status, we can't download the file if the status is in Check-out, so I thought to Check-In files before download it, but it's not possible to check-In bulk of files with in fraction of seconds, So I decided to Check-In all the files through code.

This example I explain you how to Check-In files and before Check-In how to update the Mandatory fields to the respective fields.


2. Web Service Methods:



GetListItems: This method help us to get the list or library items from Moss 2007 using Web Service.

Syntax: GetListItems(string listName,string viewName,XmlNode query,XmlNode viewFields, string rowLimit,XmlNode queryOptions, string webID);

UpdateListItems : This method help us to update the listitems against each item.

Syntax: UpdateListItems(string listName,XmlNode updates);

CheckInFile: This method help us to CheckIn file.

Syntax : CheckInFile(string pageUrl, string comment, string CheckinType);


3. Source Code:




I just create the Web reference to the project for accessing the SharePoint site and get the list of files over there. To accomplish that we have to pass the web reference URL in the below format.

Web service Url Format : "http://Site:Port/_vti_bin/lists.asmx"


using (Lists listProxy = new Lists())
{
listProxy.Url = strURL;

listProxy.UseDefaultCredentials = true;


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


DataSet ds = new DataSet();

using (StringReader sr = new StringReader(retNode.OuterXml))
ds.ReadXml(sr);


if (ds.Tables["Row"] != null && ds.Tables["Row"].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables["Row"].Rows)
{
XmlNode ndlist = listProxy.GetListAndView(libName, "");

string strBatch = "" +
"" + dr["ows_ID"] + "" +
"" + HttpUtility.UrlDecode(Convert.ToString(dr["ows_EncodedAbsUrl"])) + "" +
"aaa" +
"" + DateTime.Parse(DateTime.Now.ToString()).ToString("yyyy-MM-ddTHH:mm:ssZ") + "" +
"
";


XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.SetAttribute("PreCalc", "TRUE");
elBatch.SetAttribute("ViewName", "{18F11D0B-E5BA-4BFB-90AA-43FFAD6FE112}");
elBatch.InnerXml = strBatch;

XmlNode ndret = listProxy.UpdateListItems(strlistId, elBatch);

strBatch = ndret.OuterXml;
//Check the outerxml if it throws any error skip the check-in process else perform checkin action.
listProxy.CheckInFile(dr["ows_EncodedAbsUrl"].ToString(), "", "1");
}
}
}



4. Output:



Capture

5. Conclusion:



This article help us to updatethe list items and checkin the file in Moss 2007 using web service, hope you enjoyed a lot with this article.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: