SPWeb.GetFolder method (Guid)
Recupera o objeto de pasta com a GUID especificada.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaração
Public Function GetFolder ( _
uniqueId As Guid _
) As SPFolder
'Uso
Dim instance As SPWeb
Dim uniqueId As Guid
Dim returnValue As SPFolder
returnValue = instance.GetFolder(uniqueId)
public SPFolder GetFolder(
Guid uniqueId
)
Parâmetros
uniqueId
Type: System.GuidUm GUID que identifica a pasta.
Valor retornado
Type: Microsoft.SharePoint.SPFolder
A pasta com a GUID especificada.
Comentários
O usuário deve ter permissões de BrowseDirectories para usar esse método.
Examples
O exemplo a seguir é um aplicativo de console que demonstra duas maneiras de obter um objeto SPFolder para uma pasta chamada "Pasta de teste" na lista "Documentos compartilhados".
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As SPSite = New SPSite("https://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
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://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();
}
}
}