Solved

Retreive file summary information using c#

Posted on 2004-09-21
6
2,851 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
factory design pattern vs abstract factoy design pattern 2 83
changePi Challenge 15 75
nestparen challenge 4 55
wordlen challenge 3 46
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now