SPWeb.GetFolder 方法 (Guid)
Retrieves the folder object with the specified GUID.
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Function GetFolder ( _
uniqueId As Guid _
) As SPFolder
用法
Dim instance As SPWeb
Dim uniqueId As Guid
Dim returnValue As SPFolder
returnValue = instance.GetFolder(uniqueId)
public SPFolder GetFolder(
Guid uniqueId
)
参数
uniqueId
类型:System.GuidA GUID that identifies the folder.
返回值
类型: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("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();
}
}
}