Link to home
Start Free TrialLog in
Avatar of codeconqueror
codeconqueror

asked on

How to read file properties from the Summary tab in XP

When you right-click a file and go to Properties and then go to the Summary tab, there are several extra pieces of information being displayed (title, company, etc...).  How can you read this information via VB or VB.NET?  

I have tried using the DSO library from MS, but it doesn't work, it only works on MS documents.  I have read tons tons of posts in EE and via Google but not a single one has the solution; I've tried them all.

The reason I need this is because I am writing a small app that will read an MP3 file, extract the SongName and rename the file based on the SongName tag.  I have this working beautifully.  But, I have some files that do not have MP3 tag (or at least not that I can read in code), but it does have the proper name in the Title property on the Summary tab.  So, if I can't get the SongName from the MP3 tags, then I want to look at the Title property and use that (if it exists).

Things I have tried already:

1)  Using FSO (File System Object) - Not even close
2)  Using DSO - Not even close, only worked on MS docs
3)  Using reflection to get the assembly data; this one worked, but only for my running application, I couldn't figure out any way to specify what file's assembly data I wanted to read - THIS WAS THE CLOSEST
4)  Searching Google for a couple of hours - Nothing turned up
5)  Searching previous EE posts on the subject for a couple of hours - No actual working, accepted answers
6)  Searching MSDN for a couple of hours

Can anyone help with this?  Thank you all in advance.  

And yes, I know that there are some other programs already out there that I could use to do this for me, but that's not what I want; I want my own code and my own application that does this.  Many thanks.
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

Windows reads the MP3 tags as well, I've written some code to read all the tags from my own mp3s, and it was working for most of them. Most of the current MP3s seems to be using V2.
for the specification
http://www.id3.org/

If you look at ID3 you can find a lot of examples that are working, or with the description is not that much work to create it yourself.
Note: when I said, windows reads the MP3 tags as well, I assume that, since when I modify them, somehow Windows seems to know about that as well :D
Avatar of codeconqueror
codeconqueror

ASKER

I can already read the MP3 tags.  I am getting the SongName, Artist, Album, etc...  The problem is that some of the files I have because of the way they were ripped, do not have the normal MP3 tags for some reason.  When I extract the tag and check if it's = TAG it's not (but only for these specific mp3s), but it does have the song name in the Title property of the Summary tab in file properties.  I need to read that Title property.
if you read the first couple bytes, what does it say? ID3?
Here is the function I'm using:

When I check the first 3 characters (TAG), for this particular file it ends up blank.

Look for in the ProcessFile function posted below (am I perhaps doing something wrong?  It works for all my other MP3s):
<CODE SNIPPET>
                        FileGet(intFileHandle, sTag, lngLOF - 127, True)
                        If sTag.ToUpper <> "TAG" Then
</CODE SNIPPET>

<CODE SNIPPET>
      Private Function ProcessFile(ByVal FileNameAndPath As String, ByVal OutputPath As String) As Integer
            'Return values: 0=OK, 1=File to read doesn't exist, 2=Output path doesn't exist, 3=No MP3 tag to read
            Dim iretProcessed As Integer = 0
            If System.IO.File.Exists(FileNameAndPath) And System.IO.Directory.Exists(OutputPath) Then
                  Dim intFileHandle As Integer = FreeFile()
                  Dim sTag As New String(CType(" ", Char), 3)
                  Dim sSongName As New String(CType(" ", Char), 30)
                  Dim sArtist As New String(CType(" ", Char), 30)
                  Dim sAlbum As New String(CType(" ", Char), 30)
                  Dim sYear As New String(CType(" ", Char), 4)
                  Dim sComment As New String(CType(" ", Char), 28)
                  Dim btGenre As Byte
                  Dim btTrack As Byte
                  Dim btDummy As Byte
                  FileOpen(intFileHandle, FileNameAndPath, OpenMode.Binary, OpenAccess.Read, OpenShare.LockWrite)
                  Dim lngLOF As Long = LOF(intFileHandle)
                  If lngLOF > 128 Then
                        FileGet(intFileHandle, sTag, lngLOF - 127, True)
                        If sTag.ToUpper <> "TAG" Then
                              iretProcessed = 3
                              FileClose(intFileHandle)
                        Else
                              FileGet(intFileHandle, sSongName)
                              FileGet(intFileHandle, sArtist)
                              FileGet(intFileHandle, sAlbum)
                              FileGet(intFileHandle, sYear)
                              FileGet(intFileHandle, sComment)
                              FileGet(intFileHandle, btDummy)
                              FileGet(intFileHandle, btTrack)
                              FileGet(intFileHandle, btGenre)
                              FileClose(intFileHandle)
                              sSongName = Trim$(sSongName)
                              sArtist = Trim$(sArtist)
                              sAlbum = Trim$(sAlbum)
                              sYear = Trim$(sYear)
                              sComment = Trim$(sComment)
                              lblSongName.Text = sSongName
                              lblArtist.Text = sArtist
                              lblAlbum.Text = sAlbum
                              lblYear.Text = sYear
                              lblComment.Text = sComment
                              lblGenre.Text = TranslateGenre(btGenre)
                              lblCurrentFile.Text = FileNameAndPath
                              Me.Refresh()
                              Application.DoEvents()
                              sSongName = Replace$(sSongName, Chr(0), "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, Chr(34), "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, "\", "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, "/", "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, "?", "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, "!", "", 1, -1, CompareMethod.Text)
                              sSongName = Replace$(sSongName, "*", "", 1, -1, CompareMethod.Text)
                              If sSongName Is Nothing Then
                                    sSongName = GetFileTitle(FileNameAndPath)
                              Else
                                    If sSongName.Length = 0 Then
                                          sSongName = GetFileTitle(FileNameAndPath)
                                    End If
                              End If
                              If sSongName IsNot Nothing Then
                                    If sSongName.Length > 0 Then
                                          sSongName = sSongName & ".mp3"
                                          lblOutputFile.Text = OutputPath & "\" & sSongName
                                          If GetFolderName(FileNameAndPath) = OutputPath Then
                                                Rename(FileNameAndPath, OutputPath & "\" & sSongName)
                                          Else
                                                FileCopy(FileNameAndPath, OutputPath & "\" & sSongName)
                                          End If
                                    Else
                                          iretProcessed = 3
                                    End If
                              Else
                                    iretProcessed = 3
                              End If
                        End If
                  Else
                        FileClose(intFileHandle)
                  End If
            Else
                  If Not System.IO.File.Exists(FileNameAndPath) Then
                        iretProcessed = 1
                  ElseIf Not System.IO.Directory.Exists(OutputPath) Then
                        iretProcessed = 2
                  End If
            End If
            Return iretProcessed
      End Function
</CODE SNIPPET>

If you want I can send you or post the MP3 file if that might help.  Thanks for your assistance.  :)
If I let it pass through anyways if it is <> "TAG", then it just returns blank entries for the rest of the properties and 0 as the byte for genre, track.
ID3 v1  starts with TAG
ID3 v2 starts with ID3

on the ID3.com website you can find classes doing the work for you or you can google for them..
Or you can read the specifications and make it yourself :D
Yeah, because the specification is different from v2 :D
http://www.ambientware.com/components/ID3Util.aspx

didnt try this, but they say its free and deliver source code for use with .NET
I'm not even getting the ID3, I'm getting a blank string ("").  If it said ID3, then yeah I'd make the appropriate changes.  But I reviewed the ID3 stuff at the link you sent and this code should at least get ID3 where I'm looking for "TAG", but I'm not even getting that.  Am I doing something wrong in my code to where I wouldn't get ID3 but I would get TAG?  Nothing jumped out at me as being incorrect.
Interesing link from ambientware, hadn't run into that one.  I'll have to look at and see if I see anything that might help.  Thanks.  I'll repost my results.  If you find out anything (or see something in my code) in the meantime, let me know.
ASKER CERTIFIED SOLUTION
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omegaomega
Hello, CodeConquerer,

Re: "I have tried using the DSO library from MS, but it doesn't work, it only works on MS documents."

Do you mean DSOFile.dll?  (http://support.microsoft.com/?id=224351).

This works on "other" files, but there is a problem creating the properties if they don't already exist.  If this is the problem, see the article at http://www.codecomments.com/archive293-2006-2-813451.html for a possible workaround.  (I haven't yet tried this, but hope it works because I will need it soon.)

Cheers,
Randy
Yes, DSOFile.dll (I believe that's the filename).

The properties already exist, I just need to read them.
Hello, CodeConqueror,

What specifically is the problem?  The following sequence works for me in a customized FileStream class.

    Private mdsoFileProps As New DSOFile.OleDocumentPropertiesClass   ' File properties object.
    Private mfspFileProps As DSOFile.SummaryProperties                ' Summary properties collection.
    . . .
    mdsoFileProps.Open(Me.Name)                                  ' Me.Name is the file name whose properties are to be accessed.
    mfspFileProps = mdsoFileProps.SummaryProperties

    ' In "Title" Get property of customized class:
    . . .
            Return mfspFileProps.Title
    . . .

    End Property

As mentioned, I have a problem with the Set property.  But the Get property works fine.

Cheers,
Randy
That works, just not for these MP3s.  I could only get it to work with some MS office docs and some other files, but not these MP3s.
I'm still working on trying different MP3 formats to get it to work, but....

Back to my first question:  Does anyone know how to access the information on the Summary tab of a file when in XP w/ NTFS?  Thanks.

Thanks for your help so far guys.  Hopefully we can figure out how to do this.  :)
Without using DSO preferably.  I'd like to avoid installing and registering more components if possible.
Well, i figured out how to read the mp3 file properly (it was APE format).  Thanks for your help.

Although, this didn't directly answer my original posted question.  If anyone has any idea on how to read the summary properties, please let me know and I will open a new question and reward points.  For now, since I at least go past my problem, the point go to PockyMaster.  Thanks for your help.
You're welcome