Solved

How to programmatically modify any files properties.

Posted on 2003-12-03
6
1,609 Views
Last Modified: 2007-12-19
I am trying to traverse through a set of directories and then set the file properties, summary - title field. When you go to a file and right click on it and select properties, and the select the summary tab, you will see the Title field, plus a bunch of other fields like subject and author. All files have these regardless of what it is. I will be dealing with TIFF files and .TXT files. Does anyone know how to programmatically set these using C#? Thanks
0
Comment
Question by:JLD777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 9872318


Here's how to access the properties:


Go Here:
http://support.microsoft.com/?kbid=224351


Download the file DsoFile.exe

Save the dll to your windows/system or windows/system32 directory.  Wherever you want really.  Then register the dll.


To register the dll go to a dos prompt (or the Start Button|Run prompt) and type the following

regsvr32 <directory path of dll>\dsofile.dll

in about 5 seconds you will get a message saying "dll registered successfully"


Now... in your .NET application go into Project>References>COM tab and click the BROWSE button.  Navigate to your windows32 directory (or wherever you put your dll) and select it.  Press OK.


Now back in your code you can do one of two things...


you can either add it as a reference at the top of the page (with the "using" syntax), or you can type out the namespace the long way.


<with "using">

using System;
using DSOleFile;


PropertyReaderClass myDso = new PropertyReaderClass();
DocumentProperties myDp = dso.GetDocumentProperties(@"c:\temp\test.txt");

string author = dp.Author;
string lastEditedBy = dp.LastEditedBy;







<without "using">



using System;

DSOleFile.PropertyReaderClass dso = new PropertyReaderClass();
DSOleFile.DocumentProperties dp = dso.GetDocumentProperties(@"c:\temp\test.txt");

string author = dp.Author;
string lastEditedBy = dp.LastEditedBy;



0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 300 total points
ID: 9872387


Here is how you can itterate through a directory structure



            private void button1_Click(object sender, System.EventArgs e)
            {
                  ArrayList list = DirSearch(@"c:\temp","*.txt",new ArrayList());

                  for(int i=0;i<list.Count;i++)
                        Console.WriteLine(list[i].ToString());
            }

            private ArrayList DirSearch(string parentDir, string fileType, ArrayList fileList)
            {
                  string[] childDir;
                  string[] files;
                  
                  childDir = Directory.GetDirectories(parentDir);
                  files = Directory.GetFiles(parentDir,fileType);

                  for(int i=0;i<files.Length;i++)
                        fileList.Add(files[i]);

                  for(int i=0;i<childDir.Length;i++)
                        fileList = DirSearch(childDir[i],fileType,fileList);

                  return fileList;
            }
0
 

Author Comment

by:JLD777
ID: 9885497
_TAD_ thanks for your great answer, I tried the following (in C#)
      ...
      DSOleFile.PropertyReaderClass PR = new PropertyReaderClass();
       DocumentProperties dcs = PR.GetDocumentProperties(@"C:\imageEG.TIF");
      string test = dcs.Author;
      test = dcs.Subject;
      test = dcs.Title;
      // Set the values
      dcs.Comments = "Some comment on the file";
      dcs.Author = "Test1";
      dcs.Title = "Test2";
      dcs.Subject = "Test3";
      return;

and as you notice my file is a TIF file. Unfortunately when you modify the properties for a TIF file as shown they do not show up in the Summary tab when you view them manually. Although if you go and read them programmatically you will see that the properties indeed were set. On further research apparently this is because graph files are not Ole compliant (whatever that means..).
If you do the above for a .TXT file it works fine, but if you do it for a .TIF or a JPEG file it doesn't work so well. You won't see it when you right click and view the properties, but you can retrieve (programmatically) the values that you set (again only programmatically). If you set the property values in a TIF file manually (using the summary tab etc. ) you can NOT access them programmatically, but this only applies to TIF files and JPEG files (and graphics files since they are not Ole compliant). I am still searching for a way to get at the true Author, Subject, Title properties of the graphics file. Any help is much appreciated.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 22

Expert Comment

by:_TAD_
ID: 9885648


OLE implies drag-and-drop cababilities.  I don't know what that has to do with TIF files, but I guess I'm going to find out.


Let me see what I can do... I have yet to run into this issue, but it could be a problem for me in the future.

Thanks!  I'll keep you posted.
0
 

Author Comment

by:JLD777
ID: 9912599
I like your answer TAD and doubt there is any other info out there as to how to properly set the TIFF file and JPEG file properties. Cheers for your help - Keith.
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9912867


That's a real bummer with the TIF and JPG files...


Thanks for the points!   I'm just sorry that the solution did not work 100% as promised.


(Since I am training for a management position, this is a good time to practice passing the blame.)

I think it is Microsoft's fault for creating a process that does not work across all file types.  I wonder if they can correct this if it is brought to their attention?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question