How to get all ‘Inherited Security’ sites in your SharePoint site collection
This article is nothing new to SharePoint developers. In fact, there are better options of getting a listing of all subsites in your site collection. However, for those who are not experienced developers, this article will give you an idea of what you can do with the SharePoint web services.
STEP 1: Call the ‘Webs.asmx’ web service to get a listing of all subsites
private void GetAllInheritedSecuritySites()
{
string inheritedSites = string.Empty();
XmlNode xmlNodes = null;
WSS3_WEBS.Webs service = new WSS3_WEBS.Webs();
service.Url = @tbSiteCollection.Text + @"/_vti_bin/Webs.asmx";
//service.Credentials = new System.Net.NetworkCredential("Your User ID", "Your Password", "Your Domain");
service.UseDefaultCredentials = true;
try
{
xmlNodes = service.GetAllSubWebCollection();
//MessageBox.Show(xmlNodes.OuterXml);
}
catch (Exception ex)
{
MessageBox.Show("Service Error" + ex.ToString());
}
foreach (XmlNode node in xmlNodes.ChildNodes)
{
inheritedSites += InheritedSite(node.Attributes["Url"].Value) + "---\r\n---";
}
}
Notice that the ‘foreach’ loop is looping thru all subsites and is then calling the ‘InheritedSite’ method and passing in the URL to get the properties of the site.
STEP 2: Call the ‘SiteData.asmx’ web service for each subsite found
private string InheritedSite(string _siteUrl)
{
string inheritedSite = string.Empty;
XmlNode xmlNodes = null;
WSS3_SITEDATA.SiteData service = new WSS3_SITEDATA.SiteData();
service.Url = _siteUrl + @"/_vti_bin/SiteData.asmx";
//service.Credentials = new System.Net.NetworkCredential("Your User ID", "Your Password", "Your Domain");
service.UseDefaultCredentials = true;
WSS3_SITEDATA._sWebMetadata webMeta;
string sRoles = string.Empty;
string[] vRolesGroups;
string[] vRolesUsers;
WSS3_SITEDATA._sWebWithTime[] vWebs;
WSS3_SITEDATA._sListWithTime[] vLists;
WSS3_SITEDATA._sFPUrl[] vFPUrls;
try
{
service.GetWeb(out webMeta, out vWebs, out vLists, out vFPUrls, out sRoles, out vRolesUsers, out vRolesGroups);
switch (chkInheritedSecurity.Checked)
{
case true:
if (webMeta.InheritedSecurity.ToString() == "True")
{
inheritedSite = _siteUrl + "\r\n";
}
break;
case false:
if (webMeta.InheritedSecurity.ToString() == "False")
{
inheritedSite = _siteUrl + "\r\n";
}
break;
}
}
catch (Exception ex)
{
inheritedSite = _siteUrl + " error";
}
return inheritedSite;
}
As mentioned before, there are much cleaner ways to get this information. This example is querying for this information by communicating with the web services. You might want to consider using the SharePoint Object Model and creating a web part to do this.
Hope this helps.
.advertisement
