When you right-click on a file in Windows and select "Properties" from the menu, it opens the Properties window. On that window for most files types there's a "Summary" tab that contains a variety of information.
Is there a managed/.NET way to retrieve that information? I had assumed incorrectly that this would be a trivial thing to do and that it would all be part of some dictionary object on the System.IO.FileInfo object a开发者_如何学Pythonnd you could just feed it a string of the tag you wanted and it would return some value. I was way wrong.
In my searches all I've been finding are shell commands, mentions of api calls or installing com objects. Those are fallback solutions (and ones I would rather avoid). What I really want to know is if I'm overlooking a .NET way of accessing that information?
What you want is called Structured Storage and this information is accessible via StgOpenStorageEx
which is in Ole32.dll
. Looking at the pinvoke.net page for this method, it appears that some of the functionality can be extracted using System.IO.Packaging.StorageInfo
but that it requires some work to do this and it looks like you still have to use P/Invoke.
I had assumed incorrectly that this would be a trivial thing to do and that it would all be part of some dictionary object on the System.IO.FileInfo object and you could just feed it a string of the tag you wanted and it would return some value
System.IO.FileInfo.Attributes
Have you tried System.Diagnostics.FileVersionInfo?
var fvi = FileVersionInfo.GetVersionInfo("c:\temp.txt");
Patrick.
There's the DSOfile.dll that lets you edit these for Office documents. Unfortunately, I don't think these properties are universal for files - they won't always be available.
Just re-read your paragraph saying that COM objects are fallback solutions - however, this is the solution provided on the MS website, so I don't think you're going to do much better.
精彩评论