When is SPFile.Properties != to SPFile.Item.Properties in SharePoint?

前端 未结 4 469
逝去的感伤
逝去的感伤 2021-01-18 01:29

One of our customers has a problem that we cannot reproduce. We programmatically copy a document\'s properties to a destination file using SPFile.Properties. However, for so

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 02:06

    There is a slight difference between SPFile.Properties and SPFile.Item fields and the first one is much, much slower to call.

    You have most probably seen Microsoft Office document's "properties" window (this one - http://dradisframework.org/images/tutorial/custom_document_properties.png). These are the properties that are read when you access SPFile.Properties. Reading them is slow since there is some code infrastructure that parses the binary DOC file and finds the properties. (takes up to 30 or something milliseconds for every property access) See more here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.properties.aspx

    In SharePoint, every item is an SPListItem and its field values (and I don't use the word "properties" on purpose here) are stored in Sharepoint's content database. So, when you access SPFile.Item.Properties, you actually look at the SPListItem to which the file is attached and look at its properties from SharePoint's content database.

    What happens behind the scene, when you upload a file having some "Office properties" set, is that SharePoint copies them to same-named fields in SPListItem. (Some information about it here: http://weblogs.asp.net/bsimser/archive/2004/11/22/267846.aspx)

    This is why these properties typically have the same value, BUT it only happens if SharePoint knows how to read metadata from your file and write them back. So, in case you put a .txt file in your SharePoint store, you will not get any SPFile.Properties back.

提交回复
热议问题