BKennedy2008
asked on
Retrieve from Sharepoint 2010 list of all sites in VB
How can I retrieve the current list of all sites in Sharepoint through VB using the Imports Microsoft.SharePoint.Clien t ?
My goal is to check whether the site is already created before VB creates a new Site. I got the site creation down, but now I need to check and see if the site has already been created.
My goal is to check whether the site is already created before VB creates a new Site. I got the site creation down, but now I need to check and see if the site has already been created.
ASKER
Can you put your logic within this code below taht creates the site? Thanks
Dim clientContext As New ClientContext("http://sps.xxxx.com/")
Dim collWeb As WebCollection = clientContext.Web.Webs
Dim webCreationInfo As New WebCreationInformation()
webCreationInfo.Title = Job_Number.Text
webCreationInfo.Descriptio n = JobNme.Text
webCreationInfo.Language = 1033
webCreationInfo.Url = Job_Number.Text
webCreationInfo.UseSamePer missionsAs ParentSite = True
webCreationInfo.WebTemplat e = TemplateID
Dim oNewWebsite As Web = collWeb.Add(webCreationInf o)
Try
clientContext.ExecuteQuery ()
Catch ex As Exception
MsgBox(ex.Message)
Me.Cursor = Cursors.Default
Exit Sub
End Try
Dim clientContext As New ClientContext("http://sps.xxxx.com/")
Dim collWeb As WebCollection = clientContext.Web.Webs
Dim webCreationInfo As New WebCreationInformation()
webCreationInfo.Title = Job_Number.Text
webCreationInfo.Descriptio
webCreationInfo.Language = 1033
webCreationInfo.Url = Job_Number.Text
webCreationInfo.UseSamePer
webCreationInfo.WebTemplat
Dim oNewWebsite As Web = collWeb.Add(webCreationInf
Try
clientContext.ExecuteQuery
Catch ex As Exception
MsgBox(ex.Message)
Me.Cursor = Cursors.Default
Exit Sub
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I reduced it to this, and works great. Thanks for a starting point
Private Sub getSubWebs(path As String)
Try
Dim clientContext As New ClientContext(path)
Dim oWebsite As Web = clientContext.Web
clientContext.Load(oWebsit e, Function(website) website.webs)
clientContext.ExecuteQuery ()
For Each orWebsite As Web In oWebsite.Webs
dt.Rows.Add(orWebsite.Titl e)
Next
DataGridView2.DataSource = dt
Catch ex As Exception
End Try
End Sub
Private Sub getSubWebs(path As String)
Try
Dim clientContext As New ClientContext(path)
Dim oWebsite As Web = clientContext.Web
clientContext.Load(oWebsit
clientContext.ExecuteQuery
For Each orWebsite As Web In oWebsite.Webs
dt.Rows.Add(orWebsite.Titl
Next
DataGridView2.DataSource = dt
Catch ex As Exception
End Try
End Sub
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for BKennedy2008's comment #a40573850
Assisted answer: 500 points for Jamie McAllister MVP's comment #a40573187
for the following reason:
Modified to VB
Accepted answer: 0 points for BKennedy2008's comment #a40573850
Assisted answer: 500 points for Jamie McAllister MVP's comment #a40573187
for the following reason:
Modified to VB
Here's a C# example you can port easily.
Open in new window