SPFile.Properties Property

本文介绍如何使用 C# 和 VB.NET 更新 SharePoint 文件的元数据属性,并通过示例代码展示如何遍历文档库中的文件并显示其属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


C#VB
public Hashtable Properties { get; }
Property Value

Type: System.Collections.Hashtable
A System.Collections.Hashtable object that contains the metadata.
Remarks
The Windows SharePoint Services 3.0 object model supports updating file metadata. You can use an indexer on this property to set a value. For example, to set the value of the MyDate property for a given file to the current date and time, use the indexer and call the Update method, as follows:

[Visual Basic]

oFile("MyDate") = DateTime.Now

oFile.Update()

[C#]

oFile["MyDate"] = DateTime.Now;

oFile.Update();

Examples
The following code example iterates through the collection of files in a document library and displays the properties and values for each file.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

C#VB
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>");
        }
    }
}
The previous example displays metadata similar to the following:

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
Note
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值