SPWeb.GetFolder method (Guid)

Retrieves the folder object with the specified GUID.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

'Declaration
Public Function GetFolder ( _
	uniqueId As Guid _
) As SPFolder
'Usage
Dim instance As SPWeb
Dim uniqueId As Guid
Dim returnValue As SPFolder

returnValue = instance.GetFolder(uniqueId)

Parameters

uniqueId
Type: System.Guid

A GUID that identifies the folder.

Return value

Type: Microsoft.SharePoint.SPFolder
The folder with the specified GUID.

The user must have BrowseDirectories permissions to use this method.

The following example is a console application that demonstrates two ways of getting an SPFolder object for a folder named "Test folder" in the "Shared Documents" list.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("http://localhost")
         Using web As SPWeb = site.OpenWeb()

                If (web.DoesUserHavePermissions(SPBasePermissions.BrowseDirectories)) Then

                    ' Get a folder by server-relative URL.
                    Dim url As String = web.ServerRelativeUrl + "/shared documents/test folder"
                    Dim folder As SPFolder = web.GetFolder(url)

                    Try
                        ' Get the folder's Guid.
                        Dim id As Guid = folder.UniqueId
                        Console.WriteLine(id)

                        ' Get a folder by Guid.
                        folder = web.GetFolder(id)
                        url = folder.ServerRelativeUrl
                        Console.WriteLine(url)

                    Catch ex As System.IO.FileNotFoundException
                        Console.WriteLine(ex.Message)
                    End Try

                End If

         End Using
      End Using
      Console.ReadLine()
   End Sub
End Module
Show: