Requirement: Get reference of files inside folders in SharePoint Library using List Web Service.I have multiple files inside ChildSourceFolder” folder.
Environment:SharePoint 2013
Folder Structure:
SourcePath: DocumentLibraryName/ParentFolder/ChildSourceFolder/FileName.docx
Issue: I am not able to get the value of source file path and source file name inside the folder structure.
I need help in caml query to build proper query option to get the reference to the source file.
///called function
///<example>
///webServiceURL=”https://siteurl:9000”
///sourceLibrary=”MyDocumentLibrary”
///sourceFolderPath=”ParentFolder/ChildSourceFolder/”
///</example>
public System.Xml.XmlNode GetItemsfromLibrary(string webServiceURL,string sourceLibrary,string sourceFolderPath){
ListWebServiceReference.Lists objListService =new ListWebServiceReference.Lists();
objListService.Url = webServiceURL + "/_vti_bin/Lists.asmx";
objListService.Credentials = System.Net.CredentialCache.DefaultCredentials;
try {
System.Xml.XmlDocument xdListData =new System.Xml.XmlDocument();
System.Xml.XmlNode xnQuery = xdListData.CreateElement("Query");
System.Xml.XmlNode xnViewFields = xdListData.CreateElement("ViewFields");
System.Xml.XmlNode xnQueryOptions = xdListData.CreateElement("QueryOptions");
xnQuery.InnerXml = "";
xnViewFields.InnerXml = "";
//I need help to build proper Query Option. I am not able to get file names and file path
xnQueryOptions.InnerXml = ????;
//something like below code
// xnQueryOptions.InnerXml = "<Folder>"+ sourceFolderPath + "</Folder>";
System.Xml.XmlNode items;
if (String.IsNullOrEmpty(sourceFolderPath))
items = objListService.GetListItems(sourceLibrary, string.Empty, xnQuery,xnViewFields,string.Empty,null,null);
else
items = objListService.GetListItems(sourceLibrary, string.Empty, xnQuery,xnViewFields,string.Empty,xnQueryOptions,null);
return items;
}
catch(Exception ex) {returnnull;}
}
///calling function
System.Xml.XmlNode xnListData = GetItemsfromLibrary(webServiceURL,sourceLibrary,sourceFolderPath);
XmlNodeList oNodes = xnListData.ChildNodes;
foreach (XmlNode node in oNodes)
{
XmlNodeReader objReader =newXmlNodeReader(node);
while (objReader.Read())
{
if (objReader["ows_EncodedAbsUrl"] != null&& objReader["ows_LinkFilename"] != null)
{
sourcePath = objReader["ows_EncodedAbsUrl"].ToString();
sourceFileName = objReader["ows_LinkFilename"].ToString();
//call other function
//pass sourcePath andsourceFileName as parameter, but I am not able to get the value of these parameter
}
}
}