SiteData.GetSiteUrl Method

Dec 13, 2011 at 2:54 PM

Marc,

     I am looking to get a list of a site(s) and all its subsites including the actual site id guid number. I tried a few different options, but I do not think that the GetSite method is wrapped. Related to an earlier question. I think that that service exists in two different .asmx files and does different things for both! Not too important at this time, but it would be a great addition I think.

Dan

Coordinator
Dec 13, 2011 at 3:05 PM

Did you look at the Webs Web Service? All of its operations are wrapped and you can use GetAllSubWebCollection.

M.

Dec 13, 2011 at 3:09 PM

This does not return the guid of the sites and this is what I need. I could loop through the returned items and then use get web and see what that does.

Dec 14, 2011 at 11:13 AM
Edited Dec 14, 2011 at 1:14 PM

This is the code that I used to create a table to display the webs with the guids. Works great but would eventually like to have the GetWeb function of SiteData wrapped:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
	var webId;
	var url = "";
	var shtml = "<table width='100%' border='1'><tr><td align='center'>Site</td><td align='center'>ID</td></tr>";
	shtml += "<tr><td align='center'>Root</td><td align='center'>";
	shtml += getSiteID("https://nserc.navy.mil/peolmw/pms408");
	shtml += "</td></tr>";
	$().SPServices({
		operation: "GetAllSubWebCollection",
		async: false,
		completefunc: function(xData, Status) {
			//alert(xData.responseText);
			$(xData.responseXML).find("Webs > Web").each(function() {
				var $node = $(this);
				shtml += "<tr><td align='center'>";
				shtml += $node.attr("Title");
				shtml += "</td><td align='center'>";
				url = $node.attr("Url");
				shtml += getwebID(url);
				shtml += "</td></tr>";	
			});
		}
	});
	shtml += "</table>";
	$("#allwebs").html(shtml);
});

function getwebID(weburl) {
	var webID
	var soapEnv = "<?xml version='1.0' encoding='utf-8'?>";
	soapEnv += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
    soapEnv += "<soap:Body><GetWeb xmlns='http://schemas.microsoft.com/sharepoint/soap/'></GetWeb></soap:Body>";
    soapEnv += "</soap:Envelope>";

	$.ajax({
	    url: weburl + "/_vti_bin/SiteData.asmx",
	    beforeSend: function(xhr) {xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetWeb");},
	    type: "POST",
	    data: soapEnv,
	    dataType: "xml",
	    async: false,
	    complete: function(xData, status) {webID = $(xData.responseXML).find('WebID').text();},
	    contentType: "text/xml; charset='utf-8'"
	});
	return webID
}

function getSiteID(weburl) {
	var webID;
	var soapEnv = "<?xml version='1.0' encoding='utf-8'?>";
	soapEnv += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
    soapEnv += "<soap:Body><GetSiteUrl xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
    soapEnv += "<Url>" + weburl + "</Url>";
    soapEnv += "</GetSiteUrl></soap:Body>";
    soapEnv += "</soap:Envelope>";

	$.ajax({
	    url: weburl + "/_vti_bin/SiteData.asmx",
	    beforeSend: function(xhr) {xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetSiteUrl");},
	    type: "POST",
	    data: soapEnv,
	    dataType: "xml",
	    async: false,
	    complete: function(xData, status) {
			//$("#txtresult").val(xData.responseText); 
			webID = $(xData.responseXML).find('siteId').text();
		},
	    contentType: "text/xml; charset='utf-8'"
	});
	return webID
}

</script>
<div id="allwebs"/>
The first row is the the site id and the following rows are each web and the web id.
Coordinator
Dec 14, 2011 at 2:53 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 29, 2011 at 3:18 PM

Dan:

I've just added SiteData.GetSite to SPServices in an alpha, and it doesn't give you the GUIDs, either.

For each vWeb, you get:

<_sWebWithTime><Url>http://www.sympraxisconsulting.com</Url><LastModified>2011-12-29T16:06:04</LastModified></_sWebWithTime> 

So, only the URL and the LastModified date/time stamp. I'll keep it in the alpha, but I think you're in the same spot of having to iterate over the Webs.

M.


Dec 29, 2011 at 4:14 PM

Marc, I have to apologize for getting my post mixed up. I stated "GetSite" when I meant "GetSiteUrl" as what I posted in the code. I could kick myself for not catching that faux pa! As my code works, it is no rush, but GetSiteUrl works great!

Coordinator
Dec 29, 2011 at 4:16 PM

No worries. I'll add that operation as well. do you think any other SiteData ops are useful? There aren't that many, so maybe I should just add 'em all.

M.

Dec 29, 2011 at 5:08 PM
All sounds good to me!

Sent from my iPhone

On Dec 29, 2011, at 12:16 PM, "sympmarc"<notifications@codeplex.com> wrote:

From: sympmarc

No worries. I'll add that operation as well. do you think any other SiteData ops are useful? There aren't that many, so maybe I should just add 'em all.

M.