共用方式為


SPFile.Properties property

取得檔案的中繼資料。

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

Syntax

'宣告
Public ReadOnly Property Properties As Hashtable
    Get
'用途
Dim instance As SPFile
Dim value As Hashtable

value = instance.Properties
public Hashtable Properties { get; }

Property value

Type: System.Collections.Hashtable
System.Collections.Hashtable物件,包含中繼資料。

備註

注意事項注意事項

在這個屬性中儲存大量的資料會嚴重降低效能。不要在此屬性中儲存以上一個千位元組 (1 k) 的使用者資料。

Windows SharePoint Services 3.0物件模型支援更新檔案中繼資料。您可以使用這個屬性中的索引子設定值。例如,若要設定的指定檔案的MyDate屬性值為目前的日期和時間,使用索引子,並呼叫Update方法,如下:

[Visual Basic]

oFile("MyDate") = DateTime.Now

oFile.Update()

[C#]

oFile["MyDate"] = DateTime.Now;

oFile.Update();

Examples

下列程式碼範例會逐一查看文件庫中的檔案集合,並顯示的屬性和值的每個檔案。

這個範例要求using指示詞 (在 Visual Basic 的Imports ) 的Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間。

Dim siteCollection As SPSite = SPContext.Current.Site
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")

Dim folder As SPFolder = site.Folders("Shared Documents")
Dim files As SPFileCollection = folder.Files
Dim file As SPFile

For Each file In  files

    Dim hash As System.Collections.Hashtable = file.Properties
    Dim keys As System.Collections.ICollection = hash.Keys
    Dim key As Object

    For Each key In  keys

        Response.Write(SPEncode.HtmlEncode(key.ToString()) 
            & " :: " & SPEncode.HtmlEncode(hash(key.ToString())
            .ToString()) & "<BR>")

    Next key

Next file
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPFolder oFolder = oWebsite.Folders["Shared Documents"];
    SPFileCollection collFiles = folder.Files;

    foreach (SPFile oFile in collFiles)
    {
        System.Collections.Hashtable collHashes = file.Properties;
        System.Collections.ICollection collKeys = hash.Keys;

        foreach (object oKey in collKeys)
        {
            Response.Write(SPEncode.HtmlEncode(oKey.ToString()) 
            + " :: " + 
            SPEncode.HtmlEncode(hash[oKey.ToString()].ToString())
            + "<BR>");
        }
    }
}

前一個範例會顯示類似下列的中繼資料:

vti_author :: User_Name
vti_cachedtitle :: New Page 1
vti_metatags :: HTTP-EQUIV=Content-Language en-us GENERATOR Microsoft\ 
    FrontPage\ 5.0 ProgId FrontPage.Editor.Document 
    HTTP-EQUIV=Content-Type text/html;\ charset=windows-1252
vti_progid :: FrontPage.Editor.Document
vti_cachedbodystyle :: 
vti_modifiedby :: User_Name
vti_charset :: windows-1252
vti_sourcecontrolcheckincomment :: Comment
vti_nexttolasttimemodified :: 5/6/2003 8:16:58 PM
vti_filesize :: 6439
vti_docstoretype :: 0
vti_language :: en-us
vti_generator :: Microsoft FrontPage 5.0
vti_timelastmodified :: 5/6/2003 8:59:25 PM
vti_title :: File_Title
vti_docstoreversion :: 2
vti_sourcecontrolcookie :: fp_internal
vti_sourcecontrolversion :: V2
vti_cachedneedsrewrite :: false
vti_timecreated :: 5/6/2003 8:16:58 PM
vti_cachedcustomprops :: vti_title
vti_cachedhastheme :: false
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

請參閱

參照

SPFile class

SPFile members

Microsoft.SharePoint namespace