File summary attributes

This is a discussion on File summary attributes within the Windows Programming forums, part of the Platform Specific Boards category; How would one go about editing file summary attributes? i.e Title, Subject, Author, Comments, etc... Is there a class or ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    4

    File summary attributes

    How would one go about editing file summary attributes? i.e Title, Subject, Author, Comments, etc... Is there a class or standard function for accessing them?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Oh there's likely to be something windows specific.

    Did you start with say
    http://www.google.com/search?q=file+....microsoft.com
    ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    yes i did!!
    but I am looking for something not just window specific

    thanks for the help any way.. but bye.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I previously posted a sample that does this here (towards the bottom under DocProps). However, it is slightly LCC-WIN specific so I made a few changes to make it compatible with MSVC. It should also work with Dev-C++, but my (fairly old) version did not have adequately up-to-date header files. The code is C++ (not C). You should still check out the linked sample because there are some notes in the readme file. Obviously, this is entirely Windows specific (you did post on the Windows board). I'm not aware of nix having a similar document properties scheme.
    Code:
    /*
    Code by TMouse.
    
    Also see:
    http://users.chello.be/ws36637/properties2.html
    http://msdn.microsoft.com/library/en-us/stg/stg/writeread_sample.asp
    */
    
    #include <objbase.h>
    #include <stdio.h>
    
    #if defined(_MSC_VER)
    #pragma comment(lib, "ole32.lib")
    #endif
    
    
    // ================================================================================
    HRESULT SetDocProperties(LPCWSTR      szFile,
                             LONG         cProps,
                             PROPSPEC*    pPropSpecs,
                             PROPVARIANT* pPropVars)
    {
    	HRESULT hr;
    	IPropertySetStorage* pStg       = NULL;
    	IPropertyStorage*    pPropStg   = NULL;
    
    	// Open file. We could use StgCreateStorageEx() if we wanted to create the file.
    	hr = StgOpenStorageEx(szFile,
    	                      STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
    	                      STGFMT_ANY, 0, NULL, NULL,
    	                      IID_IPropertySetStorage, (void**) &pStg);
    
    	if (SUCCEEDED(hr))
    	{
    		// Now open the standard document properties...
    		hr = pStg->Open(FMTID_SummaryInformation,
    		                STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropStg);
    
    		// If the property set dosen't exist, we create it...
    		if (hr == STG_E_FILENOTFOUND)
    		{
    			hr = pStg->Create(FMTID_SummaryInformation, &FMTID_SummaryInformation,
    			                  PROPSETFLAG_DEFAULT,
    				          STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, &pPropStg);
    		}
    
    		if (SUCCEEDED(hr))
    		{
    			// Write Properties...
    			hr = pPropStg->WriteMultiple(cProps, pPropSpecs, pPropVars, 100);
    
    			// Commit changes to file...
    			pPropStg->Commit(STGC_DEFAULT);
    		}
    	}
    
    	if (pStg)     pStg->Release();
    	if (pPropStg) pPropStg->Release();
    
    	return hr;
    }
    
    
    // ================================================================================
    HRESULT SetDocPropertyString(LPCWSTR szFile, PROPID propid, LPCWSTR szValue)
    {
    	PROPSPEC    PropSpec    = { PRSPEC_PROPID, propid };
    	PROPVARIANT PropVariant = { 0 };
    
    	PropVariant.vt      = VT_LPWSTR;
    	PropVariant.pwszVal = (LPWSTR) szValue;
    
    	return SetDocProperties(szFile, 1, &PropSpec, &PropVariant);
    }
    
    
    // ================================================================================
    int main(void) 
    {
    	HANDLE      hFile;
    	HRESULT     hr;
    	PROPVARIANT PropVariants[3];
    	PROPSPEC    PropSpecs[3];
    
    	CoInitialize(NULL);
    
    	// Create file to play with...
    	hFile = CreateFile("TEST.TXT", GENERIC_WRITE, FILE_SHARE_READ, NULL,
    	                   OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    	CloseHandle(hFile);
    
    	// Set a single property...
    	hr = SetDocPropertyString(L"test.txt", PIDSI_COMMENTS, L"These are some comments.");
    	if (FAILED(hr)) printf("Failed to set property on test.txt. Is this drive NTFS?\n");
    
    	// Now set multiple properties at once...
    	PropSpecs[0].ulKind = PRSPEC_PROPID;
    	PropSpecs[0].propid = PIDSI_TITLE;
    	PropVariants[0].vt = VT_LPWSTR;
    	PropVariants[0].pwszVal = L"Document Summaries Sample";
    
    	PropSpecs[1].ulKind = PRSPEC_PROPID;
    	PropSpecs[1].propid = PIDSI_AUTHOR;
    	PropVariants[1].vt = VT_LPSTR;
    	PropVariants[1].pszVal = "TMouse";
    
    	PropSpecs[2].ulKind = PRSPEC_PROPID;
    	PropSpecs[2].propid = PIDSI_KEYWORDS;
    	PropVariants[2].vt = VT_LPWSTR;
    	PropVariants[2].pwszVal = L"Title, Subject, Author, Comments, Document Properties, COM, OLE";
    
    	hr = SetDocProperties(L"test.txt", 3, PropSpecs, PropVariants);
    	if (FAILED(hr)) printf("Failed to set properties on test.txt.\n");
    
    	// Set a property on a word doc (this file must already exist)...
    	hr = SetDocPropertyString(L"test.doc", PIDSI_SUBJECT, L"The wonders of...");
    	if (FAILED(hr)) printf("Failed to set property on test.doc. Does it exist?\n");
    
    	CoUninitialize();
    	printf("Press ENTER to continue...\n");
    	getchar();
    
    	return 0;
    }
    Attached Images Attached Images  
    Last edited by anonytmouse; 06-24-2005 at 11:09 AM. Reason: Made clear that code is C++ and not C.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    What other OS did you have in mind?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    thanks anonytmouse,
    You were of great help thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Help Required!!!!!
    By bobthebullet990 in forum C Programming
    Replies: 14
    Last Post: 11-27-2005, 02:56 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21