SPWeb.GetFolder method (Guid)
擷取含有指定 GUID 的資料夾物件。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
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
Type: System.Guid識別資料夾的 GUID。
傳回值
Type: Microsoft.SharePoint.SPFolder
指定的 GUID 與資料夾。
備註
使用者必須具有BrowseDirectories權限,才能使用此方法。
Examples
下列範例會示範兩種取得名為 「 測試資料夾 」,在 [共用文件] 清單中的資料夾中的SPFolder物件的主控台應用程式。
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();
}
}
}