Wednesday, December 28, 2011

Reading File Tags in VB.Net

Hi All,

There are times when we add the tags to our files. We can use the Shell32 folder to read the tags. I found a little problematic for the first timer, so adding the code to read the tags here :



Sub TestTags()
Dim fInfo As New FileInfo("Path of your File goes here")
Dim tags As String = ReadFileAttributes(fInfo)
End Sub

Public Function ReadFileAttributes(fInfo As FileInfo) As String

Dim shell As New Shell32.Shell
Dim objFolder As Shell32.Folder
Dim items As Shell32.FolderItems
Try
objFolder = shell.NameSpace(fInfo.Directory.FullName)
items = objFolder.Items
Return objFolder.GetDetailsOf(items.Item(fInfo.Name), 18)
Catch ex As Exception
Return "Caught Exception in Tags" 'exception..cannot find the tags
End Try

End Function

.

You have to add a reference to Microsoft Shell Controls and Automation from the COM tab of the Refences dialog.

HTH,
Vikas

No comments: