A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Friday, September 2, 2005

How to get a list of sites in SharePoint using .NET code?

Here is how you can get a list of sites. The following function will retrieve a list of sites from your main portal address. All site names will be written to a text file.
Function GetFolders(ByVal rootsite As String)
//rootsite contains your main portal address, for example,
http://myportal
Dim strSites As String = ""
Dim mysite As SPSite
mysite = New SPSite(rootsite)

Dim subSites As SPWebCollection = mysite.AllWebs

Dim i As Integer

For i = 0 To subSites.Count - 1

Dim lists As SPListCollection = subSites(i).Lists

Dim j As Integer

Dim siteurl As String

For j = 0 To lists.Count - 1

strSites = strSites & SPEncode.HtmlEncode(subSites(i).Title) & ": " & SPEncode.HtmlEncode(lists(j).Title) & vbCrLf

//Insert Check Rights code here!!!

Next

Next

Dim sw As StreamWriter = File.AppendText("sites.txt")

sw.WriteLine("[" & Date.Now & "]")

sw.WriteLine(strSites)

sw.Flush()

sw.Close()

MsgBox("File created successfully. See 'sites.txt'!")

End Function

No comments:

Post a Comment