-
Apr 5th, 2011, 10:49 AM
#1
[.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 ShellFile.vb file to your project.
In the example I will retrieve the frame width of a video:
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:
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.
Last edited by ForumAccount; Jul 22nd, 2011 at 11:02 AM.
Reason: Applied different styling
-
Jul 17th, 2011, 11:40 AM
#2
Junior Member
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
-
Jul 17th, 2011, 01:47 PM
#3
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Did you add the ShellFile.vb to your project?
-
Jul 18th, 2011, 01:03 AM
#4
Junior Member
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
-
Jul 20th, 2011, 11:41 AM
#5
Addicted Member
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Nice code finaly i found.
Last edited by stru4nak; Jul 20th, 2011 at 11:47 AM.
MACEDONIA 4EVER
-
Jul 20th, 2011, 11:47 AM
#6
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
Read the sentence in my first post that has bolded words in it.
-
Sep 15th, 2012, 08:07 AM
#7
New Member
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...
-
Jan 14th, 2013, 03:48 AM
#8
Member
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?
-
Jan 15th, 2013, 10:33 AM
#9
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
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.
-
Jan 15th, 2013, 10:46 AM
#10
Member
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
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:
-
Jan 15th, 2013, 02:49 PM
#11
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.
-
Jan 15th, 2013, 06:09 PM
#12
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
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.
-
Jan 16th, 2013, 03:24 AM
#13
Member
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")
Last edited by LukeVoyager; Jan 16th, 2013 at 04:57 AM.
-
Mar 19th, 2013, 02:57 PM
#14
New Member
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?
-
Apr 1st, 2013, 08:40 AM
#15
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.
-
Jun 27th, 2016, 04:40 AM
#16
New Member
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
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
-
Jul 15th, 2016, 10:58 AM
#17
New Member
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?
-
Jul 19th, 2016, 07:21 AM
#18
New Member
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
-
Feb 22nd, 2017, 02:58 AM
#19
New Member
Re: [.NET 3.5+] ShellFile - Managed Wrapper To Retrieve Extended Properties
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|