Solved

Retreive file summary information using c#

Posted on 2004-09-21
6
2,855 Views
Last Modified: 2008-01-09
I am looking for a way to retrieve summary information from a file. Such as "Title", "Subject", "Author", "Comments".
Moreover, the values you give to the attributes in the properties of the file when you right-click on it.

I am looking mainly for txt files and office documents.

I've got the following information without a problem using System.IO:

DirectoryInfo dirInfo = new DirectoryInfo(strRootPath);
DirectoryInfo[] dirs = dirInfo.GetDirectories();
int iNumOfFiles = dirInfo.GetFiles().Length;
FileInfo[] fInfo = new FileInfo[ iNumOfFiles ];
fInfo = dirInfo.GetFiles();
foreach(FileInfo fi in fInfo)
{
    lblInfo.Text +=fi.Name+" "+fi.Size.... //which I am able to get some information about each file. But not exactly what i need!
}

Thanks for the help
Joao Clementi


                                    
My environment is: Visual Studio .Net 2003 (ASP.NET and C#)
0
Comment
Question by:joaoclementi
  • 3
  • 3
6 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 250 total points
ID: 12111762
0
 

Author Comment

by:joaoclementi
ID: 12119274
Thank you... I followed the instructions and was able to refence the DSFile component but I have the following problem in the line I am suppouse to declare the PropertyReaderClass.

####################################################################################
Access is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

####################################################################################

ERROR--->PropertyReaderClass myProp = new PropertyReaderClass();
DocumentProperties dpFile = myProp.GetDocumentProperties(@"c:\test\license.txt");

I have tried modifying the permission of the files but nothing is working. I know it must be something really trivial.

Thaks for the help
0
 
LVL 19

Expert Comment

by:Desp
ID: 12119915
.txt (text file) ??? they dont have any such properties
i suppose its MS office document!
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:joaoclementi
ID: 12122162
Actually the example used a .txt file but the error happens in the line before.

I tried changing to a .doc but the point is that it's not even getting to that line of code when i debug.

ERROR--->PropertyReaderClass myProp = new PropertyReaderClass();


0
 
LVL 19

Expert Comment

by:Desp
ID: 12122339
give proper privileges to the ASP.Net on the folder where the files are located
0
 

Author Comment

by:joaoclementi
ID: 12136650
Thanks Desp, I got it working

Actually the problem occured in the component registration and not in setting the priviledges to the folder. I removed the previous registration of the dll from a folder that was located in "My Documents" and placed under the C:/DsoFile and its now working.

Another problem that I am facing is when I get the properties for the first time, everything is fine and I am able to display the information on the web page, but as soon as the page reloads the line:
DocumentProperties dpFile = myProp.GetDocumentProperties(@"c:\test\license.doc") fails giving the folowing error log:
************************************************************************
Source            : Dsofile.dll
Method            : GetDocumentProperties
Date            : 2:59:35 PM
Time            : 9/23/2004
Error            : The file you have selected has no document properties.
Stack Trace      : at DSOleFile.PropertyReaderClass.GetDocumentProperties(String sFileName)
   at WFFM.list.SetFiles()
************************************************************************
then even when I close the app and try to move or delete those files manually a warning message comes up saying that another program is using that file, but I closed all browsers and visual studio. So something is not releasing the resource, do you have any idea what that might be?

Thanks
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 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