3 Attachment(s)
[.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
This was created as a response for this thread. Basically, it is a way to read (not write) all those extra properties that Windows has. This code requires a reference to "Microsoft Shell Controls And Automation" which is under the COM tab.
You also need to add the Attachment 83393 file to your project.
In the example I will retrieve the frame width of a video:
Attachment 83394
Code:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
'//create the wrapped file by passing in a path to a file
Using file = New ShellFile("C:\Users\Public\Videos\Sample Videos\Wildlife.wmv")
'//access the extended property by name (case insensitive search)
Dim frameWidth = file.ExtendedProperties("frame width")
'//check for nothing because if you attempt to index a property
'//that doesn't exist then it will return null (nothing)
If frameWidth IsNot Nothing Then
MessageBox.Show(frameWidth.Value)
End If
End Using
End Sub
End Class
Output:
Attachment 83395
You can refer to this to see a relatively current list of valid extended properties by operating system. Or, you can just output all the extended property names that the code produces.
This code was tested on x64 Windows 7 Home Premium. Code contains Xml commenting as well.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Hello
I have looked at your post and I am trying it now
What is the shellfile defind as?? I am getting an error even though I have imported the Microsoft Shell in the Coms
thanks
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Did you add the ShellFile.vb to your project?
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
I have now .... oops
Great work BTW been looking to access this info for ages
Thanks
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Nice code finaly i found. :)
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Read the sentence in my first post that has bolded words in it.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
The use of this shellfile.vb is great. There is another article that shows how to read and write (get and set) the properties at http://www.codeproject.com/Articles/...m-Managed-Code. Slight changes need to be made to the mentioned dll files. These changes are noted in the replies for other users. It works great after the changes. Happy coding...
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Hi, I'm trying to implement this in a project I'm working on but it doesn't seem to work? I get the error message "Object reference not set to an instance of an object."
I've imported ShellFile.vb into my project and the code I am running is the same as the example you have put, however I have changed the video path.
Any suggestions?
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Quote:
Originally Posted by
LukeVoyager
Hi, I'm trying to implement this in a project I'm working on but it doesn't seem to work? I get the error message "Object reference not set to an instance of an object."
I've imported ShellFile.vb into my project and the code I am running is the same as the example you have put, however I have changed the video path.
Any suggestions?
Please provide the stack trace of the error message.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
How do I do this?
Sorry I have never had an error that's needed a stack trace to handle it. I've tried putting Msgbox(System.Environment.StackTrace) but that is before exception.
The exception is happening on the code "Dim frameWidth = file.ExtendedProperties("Frame width")" and I have to put Msgbox(System.Environment.StackTrace) before this other wise I get no message box.
Do you want the output of that?
EDIT: Sorry I have just figured it out :P
Quote:
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=videoScan
StackTrace:
at videoScan.Form1.Button1_Click(Object sender, EventArgs e) in D:\Docs\Visual Basic\videoScan\videoScan\Form1.vb:line 12
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at videoScan.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
No, wrap the code in a Try Catch Block and place a breakpoint on the Catch clause. Drill into the exception properties (View Details) and retrieve that stacktrace. You can also go to Debug > Breakpoints > Common Language Runtime Exceptions and ensure that Thrown is checked.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Quote:
Originally Posted by
LukeVoyager
........
however I have changed the video path.
Any suggestions?
Are you sure the path is correct? I get a very similar error if the file does not exist. May not be your problem, but worth checking.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
This is the only thing that was under Stacktrace -> at videoScan.Form1.Button1_Click(Object sender, EventArgs e) in D:\Docs\Visual Basic\videoScan\videoScan\Form1.vb:line 12
Got there by clicking View Details>system.NullReferenceExecption>Stacktrace.
Just checked the path and it's fine, thanks for the suggestion :)
EDIT: If it helps, the error occurs on this line -> Dim frameWidth = file.ExtendedProperties("Frame width")
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
I'm getting nothing !
I tested a lot of propertys (name, size, etc...), I always get "nothing" !
This is the code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using file = New ShellFile("C:\Users\Administrador\Downloads\videos\convertir\escapada.avi")
Dim name = file.ExtendedProperties("Name")
If name IsNot Nothing Then
MessageBox.Show(name.Value)
Else
MsgBox("nothing")
End If
End Using
End Sub
End Class
Why I can't get any value?
Maybe the "shellFile" class needs a specific Windows service running or something?
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
For those people who are having problems getting it to return any values - you may not be showing file extensions in Windows Explorer. The ShellFile.vb GetCollection procedure is trying to compare "Picture1.jpg" to "Picture1" - which don't match, and no extended properties are returned.
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Quote:
Originally Posted by
bushmobile
For those people who are having problems getting it to return any values - you may not be showing file extensions in Windows Explorer. The ShellFile.vb GetCollection procedure is trying to compare "Picture1.jpg" to "Picture1" - which don't match, and no extended properties are returned.
Thanks for the blog it was very helpful:check::thumb:
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
In VB.net 2010 on Win 7 Enterprise the values seem to have a hidden character at the beginning.
Example:
I need the frame rate for a calculation but in the code below, fr is always zero:
Code:
' Get frame rate
Dim fr As Double
Dim fps = file.ExtendedProperties("frame rate")
If fps IsNot Nothing AndAlso fps.Value <> "" Then
fr = Val(fps.Value)
TextBox_Feedback.AppendText("Frame rate: " + vbTab + fr.ToString + " frames/sec" + vbCrLf)
' ### Debug
Dim tmpStr As String
tmpStr = fps.Value
Debug.Print(tmpStr + "; " + Str2Hex(tmpStr, True))
' ### End debug
Else
TextBox_Feedback.AppendText("Frame rate: " + vbTab + "Unknown" + vbCrLf)
End If
'Str2Hex' produces the ASCII codes, in Hex, for the characters in the input string (borrowed from one of my other projects for debugging purposes here).
The feedback text box shows: "Frame rate: 0 frames/sec"
and the immediate window shows: "23 frames/second; 3F 32 33 20 66 72 61 6D 65 73 2F 73 65 63 6F 6E 64"
So it looks like fps.value returns "23 frames/second" but in reality there is a hidden ASCII 3F (should be shown as '?') at the beginning and that makes Val return zero every time.
I can get the correct value (on this machine) by discarding the first character:
Code:
fr = Val(Mid(fps.Value,2))
Will Windows always include that hidden character? Or will the fixed code produce the wrong value on other versions?
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Hello,
First , thanks for this post it was very usefull to me :)
I used it in my application and it worked fine,but when I tried to run my application on another computer
I got this Eror:
Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch6'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Do you know somthing about this??
Please help me, it very urgent to me
Thanks in advance
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Quote:
Originally Posted by
dina123456
Hello,
First , thanks for this post it was very usefull to me :)
I used it in my application and it worked fine,but when I tried to run my application on another computer
I got this Eror:
Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch6'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Do you know somthing about this??
Please help me, it very urgent to me
Thanks in advance
I have the same error. Anyone knows how to fix this?
Thanks