masterME

masterME

  • NA
  • 1
  • 0

Displaying the File Property Dialog in (VB).NET

May 12 2005 12:45 AM
I've been searching for a way to display the file property dialog (the one that comes up when you right click and select properties on any file). I can find the code to do it in vb6 but not in .NET I've even tried to modify the code I found for vb6 and use it for .NET but I get the error "An unhandled exception of type 'System.NullReferenceException' occurred in Property Dialog vb6.exe Additional information: Object reference not set to an instance of an object." Any suggestions? Thanks in advance! Here is the code I'm using: Public Class Form1 Inherits System.Windows.Forms.Form Private Const SW_SHOW = 5 Private Const SEE_MASK_INVOKEIDLIST = &HC Private Structure SHELLEXECUTEINFO Public cbSize As Long Public fMask As Long Public hwnd As Long Public lpVerb As String Public lpFile As String Public lpParameters As String Public lpDirectory As String Public nShow As Long Public hInstApp As Long End Structure Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef s As SHELLEXECUTEINFO) As Long Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sFileName As String sFileName = InputBox("Enter Full Path/Name of file to view Properties for :", "Show File Properties", "c:\systeminfo.ini") If Len(sFileName) = 0 Then MsgBox("You must enter a filename") Exit Sub End If If Len(Dir(sFileName)) = 0 Then MsgBox("File : " & sFileName & " cannot be found") Exit Sub End If DisplayFileProperties(sFileName) End Sub Public Sub DisplayFileProperties(ByVal sFullFileAndPathName As String) Dim shInfo As SHELLEXECUTEINFO With shInfo .cbSize = Len(shInfo) .lpFile = sFullFileAndPathName .nShow = SW_SHOW .fMask = SEE_MASK_INVOKEIDLIST .lpVerb = "properties" End With ShellExecuteEx(shInfo) '<---- Error occurs HERE End Sub End Class