Recently I came across a scenario where I had to create a console application for getting all sub sites inside a particular SharePoint site collections using SharePoint web services. I used GetAllSubWebCollection() method in Webs.asmx web service. Well following are the steps:-
Steps:
Steps:
- Add "{your site coll url}/_vti_bin/Webs.asmx" as web reference.
- Use the GetAllSubWebCollection() method in Webs.asmx webservice to get all sub sites and site collections.
- Point to remember - User should have atleast "Read" permission to all the sites.
Code Snippet
- class Program
- {
- static void Main(string[] args)
- {
- //webs object from the service reference named "WebRef"
- WebRef.Webs myweb = new WebRef.Webs();
- //Enter you network credentials
- myweb.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
- //Replace {your site coll url} with your site collection url
- myweb.Url = "{your site coll url}/_vti_bin/Webs.asmx";
- //Get a collection of all the subsites inside the site collection
- XmlNode objXmlNode = myweb.GetAllSubWebCollection();
- XmlNodeList objNodelist = objXmlNode.ChildNodes;
- foreach (XmlNode objNode in objNodelist)
- {
- Console.WriteLine(objNode.Attributes["Url"].Value.ToString());
- }
- Console.ReadLine();
- }
- }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.