Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to read the properties(Like title,author,Page count etc.,) of files using iPropertyStorage? anyone know the article/samples in c# 2.0 please post it

Actually,

I'm trying to programatically (using c#) read the file properties (Title, Summary, Author, Comments etc.... The stuff that shows up on the Summary tab when you see the properties of a file).

FileInfo and FileSystemInfo classes expose only the standard properties (create time, mod time etc..) so i'm trying to use IPropertyStorage.but i'm new to IPropertyStorage. any one know the article/samples post it will be helpful.
:)

ya i'm using c# 2003
Posted
Updated 16-Feb-10 2:38am
v6
Comments
Ramakrishnan Seerangasamy 6-Jun-11 7:31am    
If the problem is solved, could you please provide the solution.

rdkcds wrote:
anyone know the code in c# 2.0 please post it

rdkcds wrote:
any one know the solution post it will be helpful.


No one here is gonna do all the coding for you. You have to prove that you've actually tried writing some code on your own, then we can help with the specific problems.
 
Share this answer
 
are you using C#2003?,Your Question unable to understand me(any one also),So Write what exactly,i will answer you.
 
Share this answer
 
Here is some code I've inherited in my job:

public string GetProperty(SummaryPropId summaryPropertID)
{
    IPropertySetStorage pssSetStorage = null;
    Guid guidPropertySetStorage = new Guid("0000013A-0000-0000-C000-000000000046");
    Guid guidSummaryProperties = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
    IPropertyStorage psStorage = null;
    PropSpec[] pscSpecs = new PropSpec[1];
    PropVariant[] pvValues = new PropVariant[1];

    try
    {
        //Exit if file does not exist
        if (!fiSource.Exists) return null;
        // Open the file and its property set stream
        uint hresult = ole32.StgOpenStorageEx(fiSource.FullName, (int)(STGM.DIRECT_SWMR | STGM.READ | STGM.SHARE_DENY_NONE), (int)STGFMT.FILE, 0, System.IntPtr.Zero, System.IntPtr.Zero, ref guidPropertySetStorage, ref pssSetStorage);
        // Open the Summary Information property set
        int hresult2 = pssSetStorage.Open(ref guidSummaryProperties, (int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE), out psStorage);
        // Specify the property to be retrieved
        pscSpecs[0].ulKind = 1;
        pscSpecs[0].Name_Or_ID = new IntPtr((int)summaryPropertID);
        // Retrieve the value
        hresult2 = psStorage.ReadMultiple(1, pscSpecs, pvValues);
        // Release the Com objects
        Marshal.ReleaseComObject(psStorage);
        Marshal.ReleaseComObject(pssSetStorage);
        psStorage = null;
        pssSetStorage = null;
    }
    catch (Exception excException)
    {
        AuditMethodError(excException, System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " - " + excException.StackTrace);
    }
    finally
    {
        pssSetStorage = null;
        psStorage = null;
        pscSpecs = null;
        pvValues = null;
    }
    return Marshal.PtrToStringUni(pvValues[0].pointerValue);
}


The problem is that when it gets to the line int hresult2 = pssSetStorage.Open(ref guidSummaryProperties, (int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE), out psStorage) I'm receiving this exception:

excException = {"Object reference not set to an instance of an object."}

Here is my interface declaration:

C#
[ComVisible(true), ComImport(), Guid("0000013A-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertySetStorage
{
    uint Create([In] ref System.Guid rfmtid, [In] IntPtr pclsid, [In] int grfFlags, [In] int grfMode, ref IPropertyStorage propertyStorage);
    int Open([In] ref System.Guid rfmtid, [In] int grfMode, [Out] out IPropertyStorage propertyStorage);
}


Here is my STGM enumeration:

C#
public enum STGM : int
{
    READ = 0x00000000,
    WRITE = 0x00000001,
    READWRITE = 0x00000002,
    SHARE_DENY_NONE = 0x00000040,
    SHARE_DENY_READ = 0x00000030,
    SHARE_DENY_WRITE = 0x00000020,
    SHARE_EXCLUSIVE = 0x00000010,
    PRIORITY = 0x00040000,
    CREATE = 0x00001000,
    CONVERT = 0x00020000,
    FAILIFTHERE = 0x00000000,
    DIRECT = 0x00000000,
    TRANSACTED = 0x00010000,
    NOSCRATCH = 0x00100000,
    NOSNAPSHOT = 0x00200000,
    SIMPLE = 0x08000000,
    DIRECT_SWMR = 0x00400000,
    DELETEONRELEASE = 0x04000000
}


Does anyone have any suggestions?
 
Share this answer
 
Comments
Ramakrishnan Seerangasamy 6-Jun-11 4:42am    
I'm getting the following exception "could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND))" when excuting the following statement

int hresult2 = propSetStorage.Open(ref fmtid_SummaryProperties,
(int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE),
out propStorage);

Note: The physical file exits in the specified location

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900