Solved

Accessing File Properties (such as Title, Subject,Author,Keywords etc...) from .NET

Posted on 2004-09-05
7
1,518 Views
Last Modified: 2009-07-21
In Windows, when I look at the properties for a file, I see a summary tab that has the Title, Subject, Author, Keywords and Comments.

Can I access these through .NET (I write in C#)?

I would like to develop an image applicaton that reads the Comments from the Summary tab of the file properties to use as a caption for the image - ideally I would love to be able to read and write these properties.

I can't find anything in System.IO, but I am looking for something like:

//get the comments from the summary
string stCaption = File.Properties.Comments;

The application will run on a windows server.

Any ideas?

Thanks in advance
0
Comment
Question by:greenguy
7 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 500 total points
ID: 11987916
Have a look at the project called AdvancedFileProperties. Might be exactly what you are looking for.
http://www.coad.net/Products/
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11989379
This link here should help:

http://builder.com.com/5100-6373_14-5285107.html



<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script Language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {

      // path to directory
      string strPath = "E:/users/john/personal/files/";
      
      // create an instance of the DirectoryInfo object
      DirectoryInfo objTestDirectory = new DirectoryInfo(strPath);      

      if(objTestDirectory.Exists) {
            output.Text = "Yes, the directory <b>" + strPath + "</b> exists.";
      } else {
            output.Text = "No, the directory <b>" + strPath + "</b> does not exist.";
      }
}
</script>
<html>
<head></head>
<body>
<asp:label id="output" runat="server" style="font: 14px, Arial" /> </body> </html>



<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script Language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {

      // path to the file
      string strFilePath = "E:/users/john/personal/files/Test_Document.doc";

      // create an instance of the FileInfo object
      FileInfo objTestFile = new FileInfo(strFilePath);      

      if(objTestFile.Exists) {
            output.Text = "The file <b>" + strFilePath + "</b> was found. Here is more information: <br />";
            output.Text += "Name: " + objTestFile.Name + "<br />";
            output.Text += "Location: " + objTestFile.FullName + "<br />";
            output.Text += "Created on: " + objTestFile.CreationTime + "<br />";
            output.Text += "Last modified on: " + objTestFile.LastWriteTime + "<br />";
            output.Text += "File size (in bytes): " + objTestFile.Length.ToString() +
"<br />";                        
            output.Text += "Extension: " + objTestFile.Extension;
      } else {
            output.Text = "Sorry, the  file <b>" + strFilePath + "</b> was not found.";
      }      
}
</script>
<html>
<head></head>
<body>
<asp:label id="output" runat="server" style="font: 14px, Arial"/> </body> </html>

Fritz the Blank
0
 
LVL 4

Author Comment

by:greenguy
ID: 11992697
Fritz - I appreciate your detailed response; however, I would like to be able to access the Comments and Author properties specifically, and they are not offered in the standard System.IO namespace (that I am aware of).

Slim - That was exactly what I was looking for, almost.  To use that, I would need to register the com object - which works great on my machine, but my web host doesn't offer me that option.  They already compiled the most useful bit of code, so I can't see how they did it or make much use of it.  

That may be as close as I get.

Other thoughts?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11992727
>>.and they are not offered in the standard System.IO namespace (that I am aware of).<<

I just did a check and you are, unfortunately, correct about that.

FtB

0
 
LVL 4

Author Comment

by:greenguy
ID: 11993180
I found an acceptable answer for now - I was poking around the System.Drawing namespace, and found the PropertyItems collection, which has the comments for .jpg files.

The following code will list all of the various property items for a particular file - including the advanced properties:

System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("test.jpg"));

PropertyItem[] items = img.PropertyItems;

foreach(PropertyItem p in items)
{
      Response.Write("<ul>");
      Response.Write("<li>ID: 0x"+p.Id.ToString("x")+"<br>");
      Response.Write("<li>Length: "+p.Len.ToString()+"<br>");
      Response.Write("<li>Type: "+p.Type.ToString()+"<br>");
      Response.Write("<li>Value: "+System.Text.Encoding.ASCII.GetString(p.Value)+"<br>");
      Response.Write("</ul>");
}

Thanks for the help though.

Any thoughts about what I should do for points?  

Slim - your answer would have worked if I could register the com object on my server.

Thoughts?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12001906
Here are some guidelines:

http://www.experts-exchange.com/Web/Web_Languages/ASP/help.jsp#hs5

Good luck with your project,

FtB
0
 

Expert Comment

by:mckenzieGregory
ID: 23114997
A reference is available at http://www.codeproject.com/KB/graphics/exifextractor.aspx with a title of EXIFextractor library to extract EXIF information.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding Datediff to staistics page 2 56
INNER JOIN ? 8 45
Using Classic ASP inside HTML pages 2 59
rebind a grid after user clicks on node in treeview 1 34
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

11 Experts available now in Live!

Get 1:1 Help Now