How to paly with files inside folders…!


Hi All, Perhaps this code will be a useful one to play with folders and files….! Write this code behind the main form……….. just copy it and paste it…. it will work…
 

Imports Microsoft.SharePoint

Imports

Microsoft.SharePoint.Administration

Imports

System.Diagnostics.Process

Public

Class FrmMain

‘Global Variables

Dim spglobaladmin As New SPGlobalAdmin

Dim spvs As SPVirtualServer

Dim mylist As SPList

Dim myweb As SPWeb

Dim mysite As SPSite

Dim mywebcol As SPWebCollection

Dim myfoldercol As SPFolderCollection

Dim myfolder As SPFolder

Dim myfilecol As SPFileCollection

Dim myfile As SPFile

 

 

Private Sub GetAllVS()

‘This function will get all virtual servers on the machine

Try

For Each spvs In SPGlobalAdmin.VirtualServers

If (spvs.ContentDatabases.Count > 0) Then ‘ Excludes central adminstration site

CbVirtualServers.Items.Add(spvs.Url.ToString)

End If

Next

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

Private Sub showproperties(ByVal sender As String)

‘This code show the properties of Selected VS in grid

Dim url As New Uri(sender)

PropertyGrid.SelectedObject = url

End Sub

Public Sub showlist()

Try ‘ This code show lists in ComboBox

CbLists.Items.Clear()

CbLists.SelectedText =

""

Dim strUrl As String = CbVirtualServers.SelectedItem.ToString

‘Dim mysite As New SPSite(strUrl)

mysite =

New SPSite(strUrl)

myweb = mysite.OpenWeb

For Each mylist In myweb.Lists

CbLists.Items.Add(mylist.Title.ToString)

Next

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

Private Sub GetAllSite(ByVal sender As String)

Try

TVAllsites.Nodes.Clear()

mysite =

New SPSite(sender)

mywebcol = mysite.AllWebs

For Each myweb In mywebcol ‘ This code papulates the comboBox with top level sites

If (myweb.Webs.Count > 0) Or (myweb.IsRootWeb) Then ‘Check for top level site….!

TVAllsites.Nodes.Add(myweb.Title.ToString)

End If

Next

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

GetAllVS()

‘This function gets all Virtual Server in ComboBox

End Sub

Private Sub CbVirtualServers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbVirtualServers.SelectedIndexChanged

TVAllsites.Nodes.Clear()

CbLists.Items.Clear()

CbListItems.Items.Clear()

CbLists.Update()

CbListItems.Update()

GetAllSite(CbVirtualServers.SelectedItem.ToString)

‘This function gets toplevel sites of a virtual server selected in combo BOX

showproperties(CbVirtualServers.SelectedItem.ToString)

‘Shows property of site in Property Grid

End Sub

Private Sub TVAllsites_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TVAllsites.AfterSelect

CbLists.Items.Clear()

CbLists.SelectedText =

""

showlist()

End Sub

Private Sub CbLists_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbLists.SelectedIndexChanged

Try

If (CbLists.SelectedItem = "Shared Documents") Then

CbListItems.Items.Clear()

CbListItems.Update()

For Each myweb In mysite.AllWebs

myfoldercol = myweb.Folders

For Each myfolder In myfoldercol

myfilecol = myfolder.Files

If (myfolder.Name = CbLists.SelectedItem.ToString) Then

For Each myfile In myfilecol

CbListItems.Items.Add(myfile.Name.ToString)

Next

Else

End If

Next

Next

Else

CbListItems.Items.Clear()

CbListItems.Update()

Dim name As String = CbLists.SelectedItem.ToString

‘Dim mysite As New SPSite(CbVirtualServers.SelectedItem.ToString)

mylist = mysite.OpenWeb.Lists(name)

myweb = mysite.OpenWeb

Dim mylistitem As SPListItem

For Each mylistitem In mylist.Items

CbListItems.Items.Add(mylistitem(2).ToString)

Next

End If

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

Private Sub CbListItems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbListItems.SelectedIndexChanged

End Sub

End

Class

 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: