Export (0) Print
Expand All

SPWeb.GetFolder Method (Guid)

Retrieves the folder object with the specified GUID.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

public SPFolder GetFolder(
	Guid 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.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
                    if (web.DoesUserHavePermissions(SPBasePermissions.BrowseDirectories))
                    {
                        // Get a folder by server-relative URL.
                        string url = web.ServerRelativeUrl + "/shared documents/test folder";
                        SPFolder folder = web.GetFolder(url);

                        try
                        {
                            // Get the folder's Guid.
                            Guid id = folder.UniqueId;
                            Console.WriteLine(id);

                            // Get a folder by Guid.
                            folder = web.GetFolder(id);
                            url = folder.ServerRelativeUrl;
                            Console.WriteLine(url);
                        }
                        catch (System.IO.FileNotFoundException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
            }
         }
         Console.ReadLine();
      }
   }
}
Show:
© 2015 Microsoft