Solved

Extended File Attributes - ASP.net 3.5

Posted on 2008-10-20
3
719 Views
Last Modified: 2012-05-05
Is there any way to access extended attributes of a file? Specifically I am referring to attributes such as; Title, Author, Comments, Keywords?Tags (all can be found by right-clicking a file and then clicking summary). Are these attributes accessible through ASP.net 3.5? VB in particular but C# is fine.
0
Comment
Question by:Patrick_Nisbet
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22768242
please find sample code
private void btnProperties_Click(object sender, EventArgs e)
 

{
 

this.txtProperties.Text = null;
 

sourceFileName = null;
 

openFileDialog.ShowDialog();
 

if (!System.IO.File.Exists(sourceFileName))
 

{
 

MessageBox.Show("The selected file either does not exist or you didn't pick any.");
 

return;
 

}
 

this.ClientSize = new System.Drawing.Size(415, 158);
 

this.txtProperties.Show();
 

this.btnHide.Show();
 

StringBuilder stbOutput = new StringBuilder("");
 

System.IO.FileAttributes Attributes = System.IO.File.GetAttributes(sourceFileName);
 

stbOutput.Append("Date of Creation: " + System.IO.File.GetCreationTime(sourceFileName) + "rn");
 

stbOutput.Append("Date of Modification: " + System.IO.File.GetLastWriteTime(sourceFileName) + "rn");
 

stbOutput.Append("Date of Last Access: " + System.IO.File.GetLastAccessTime(sourceFileName) + "rn");
 

stbOutput.Append("Attributes: rn");
 

stbOutput.Append("Archive: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Archive) == (System.IO.FileAttributes.Archive)) + " ");
 

stbOutput.Append("Directory: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Directory) == (System.IO.FileAttributes.Directory)) + "rn");
 

stbOutput.Append("Encrypted: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Encrypted) == (System.IO.FileAttributes.Encrypted)) + " ");
 

stbOutput.Append("Hidden: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Hidden) == (System.IO.FileAttributes.Hidden)) + "rn");
 

stbOutput.Append("Normal: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Normal) == (System.IO.FileAttributes.Normal)) + " ");
 

stbOutput.Append("Read-only: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.ReadOnly) == (System.IO.FileAttributes.ReadOnly)) +"rn");
 

stbOutput.Append("System: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.System) == (System.IO.FileAttributes.System)) + " ");
 

stbOutput.Append("Temporary: " + Convert.ToBoolean((Attributes & System.IO.FileAttributes.Temporary) == (System.IO.FileAttributes.Temporary)));
 

txtProperties.Text = stbOutput.ToString();
 

}

Open in new window

0
 

Author Comment

by:Patrick_Nisbet
ID: 22769876
Hi,

Thanks for your reply. This code looks like it lists the standard file FileAttributes but not the extended one like Title, Author, Comments, Keywords/Tags.
It these ones I need to access.
Thanks
0
 

Accepted Solution

by:
Patrick_Nisbet earned 0 total points
ID: 22818891
Hi
I found the solution of Expert Exchange though there was a lot of confusion as to whether it worked on non-Office file or jpgs. It does. You need to download in and register on your server the DSOFile. Check this out:
http://www.microsoft.com/technet/scriptcenter/resources/tales/sg0305.mspx
Some of my code is below. I read the contents of a directory (jpgs and pdfs) and then display the contents with the extented information.
Thanks for your help

        Dim myDirInfo As DirectoryInfo

        Dim arrFileInfo As Array

        Dim myFileInfo As FileInfo
 
 

        ' Dim myContents As String = filepath_id & " - " & mydirectory_file & " - " & myFilter & " - " & strLastPath & "<table width='100%'>"

        Dim myContents As String = "<div id='title_div'></div><table width='100%'>"
 

        Try
 

            ' Get Directory & File Info

            myDirInfo = New DirectoryInfo(strPath)
 

            arrFileInfo = myDirInfo.GetFiles()
 

            Dim myExcludeArray As Array

            Dim myRFileTruncated As String

            Dim myDisplayPrefix As String

            Dim myDisplaySuffix2 As String
 

            ' Iterate the FileInfo objects and extract te data

            For Each myFileInfo In arrFileInfo
 

                Dim objFile As Object = CreateObject("DSOFile.OleDocumentProperties")

                objFile.Open(myFileInfo.FullName, "True")
 

                Select Case filepath_id
 

                    Case "cashe"       'cashe
 

                        If InStr(myDisplaySuffix, "`") > 0 Then

                            myDisplayPrefix = Left(myDisplaySuffix, InStr(myDisplaySuffix, "`") - 1)

                            myDisplaySuffix2 = Mid(myDisplaySuffix, InStr(myDisplaySuffix, "`") + 1)

                        Else

                            myDisplayPrefix = ""

                            myDisplaySuffix2 = myDisplaySuffix

                        End If
 
 
 

                        If InStr(myFilter, "|") > 0 Then
 
 
 

                            If InStr(myFileInfo.Name, myFileSuffix) <> 0 And InStr(myFileInfo.Name, "_work.jpg") = 0 And InStr(myFileInfo.Name, "_solutions") = 0 And InStr(myFileInfo.Name, "A_2002") = 0 And InStr(myFileInfo.Name, "2001") = 0 And InStr(myFileInfo.Name, "AD") = 0 And InStr(myFileInfo.Name, "CH") = 0 And InStr(myFileInfo.Name, "LE") = 0 And InStr(myFileInfo.Name, "EA") = 0 And InStr(myFileInfo.Name, "OR") = 0 Then
 

                                myContents = myContents & "<tr valign='top'><td><a href='download.aspx?FileName=" & myFileInfo.Name & "&dir=" & myDir & "'><img src='" & myResources_URL & myDisplayDirectory & "\" & myDisplayPrefix & Left(myFileInfo.Name, Len(myFileInfo.Name) - myDisplayCutOff) & myDisplaySuffix2 & ".jpg' border='0' /></a></td>"

                                myContents = myContents & "<td><a href='download.aspx?FileName=" & myFileInfo.Name & "&dir=" & myDir & "'>" & myFileInfo.Name & "<br />" & objFile.SummaryProperties.Keywords & "</a></td>"

                                myContents = myContents & "<td>" & myFileInfo.Length & "</td>"

                                myContents = myContents & "<td>" & myFileInfo.Extension & "</td></tr>"
 

                            End If
 

                        Else
 

                            If InStr(myFileInfo.Name, myFileSuffix) <> 0 And InStr(myFileInfo.Name, "_work.jpg") = 0 And InStr(myFileInfo.Name, myFilter) <> 0 And InStr(myFileInfo.Name, "A_2002") = 0 And InStr(myFileInfo.Name, "2001") = 0 Then
 

                                myContents = myContents & "<tr valign='top'><td><a href='download.aspx?FileName=" & myFileInfo.Name & "&dir=" & myDir & "'><img src='" & myResources_URL & myDisplayDirectory & "\" & myDisplayPrefix & Left(myFileInfo.Name, Len(myFileInfo.Name) - myDisplayCutOff) & myDisplaySuffix2 & ".jpg' border='0' /></a></td>"

                                myContents = myContents & "<td><a href='download.aspx?FileName=" & myFileInfo.Name & "&dir=" & myDir & "'>" & myFileInfo.Name & "</a></td>"

                                myContents = myContents & "<td>" & CInt(myFileInfo.Length / 1000) & "K</td>"

                                myContents = myContents & "<td>" & myFileInfo.Extension & "</td></tr>"
 

                            End If
 

                        End If
 

End Select

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot upload files above 1mb IIS7 11 39
Any Third party toll for Integrating chat system on ASP.NET ? 2 34
Remove greater than sign 3 42
Connection String 16 42
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

13 Experts available now in Live!

Get 1:1 Help Now