Getting selected files filepath without OpenFileDialog - vb.net

I was wondering if there is anyway to get the file path of a selected file. I have registered a hotkey in reference to this.
E.g. RegisterHotKey(Me.Handle, 100, MOD_CONTROL Or MOD_SHIFT, Keys.D2)
Which will do certain actions on pressing ctrl, shift and 2. What i want to do is to get the path of a selected file WITHOUT opening OpenFileDialog
e.g. i select mydoc.doc located on my desktop, press ctrl shift and 2, and it will msgbox out the location of the file.
(meaning i click the file mydoc.doc on my desktop, press my hotkey and get the file location. Is there anyway to do this? (Just like how you would click a file in a folder to copy and paste it to another location, i want to click the file press my hotkey and msgbox out its location))
Is there anyway to do this or any direction anyone can point me in?Because i can't find any API which does this...
Thanks!
EDIT:
After reading all the updates and the several links here and there, I started to construct my own function for this, I'm just at the part to determine how many selected icons there are, but i keep getting back 0 icons is there something wrong with what I'm doing?
Public Function getDesktopFiles() As String
Dim vhandle As IntPtr = FindWindow("Progman", "Program Manager")
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SHELLDLL_DefView", vbNull)
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SysListView32", "FolderView")
Dim vItemcount As IntPtr
vItemcount = SendMessage(vhandle, LVM_GETSELECTEDCOUNT, 0, 0)
Return vItemcount
End Function

This question has a link to a Raymond Chen blog post which will give you the API calls you require, you will need to convert it to VB but it is based on COM so should be easy. The other answer to that question gives the C# version of Raymond's code...
Edited to add specifics:
1. Include project references to Microsoft Internet Controls (to get the SHDocVw namespace) and Microsoft Shell Controls and Automation (to get the Shell32 namespace)
2. Use SHDocVw.ShellWindows to get an enumeration of open browser windows.
3. Try to cast each item as a ShellBrowserWindow, and then try to cast the Document property as a Shell32.IShellFolderViewDual2 object.
4. The FocusedItem property gives the selected item.
VB.NET code:
Dim windows As New SHDocVw.ShellWindows
For Each window As Object In windows
Dim browser As SHDocVw.ShellBrowserWindow = window
Dim folder As Shell32.IShellFolderViewDual2 = browser.Document
Console.WriteLine(folder.FocusedItem.Path)
Next

Related

Automaticaly open xls file on program start?

To provide our users to edit excel files without ms excel, we have made a simple app with visual studio 2012 and devexpress Spreadsheet module.
It is very simple to open excel file and use it.
But now only one excel file is being used (with multiple sheets), and I would like the file being used to be opened always on startup.
If I add the path and filename to command line arguments, noting happens...
Using devexpress components is very different then vanilla code for me, I am a complete beginner here, so I have no idea how to continue - can someone, please point me in the right direction?
I have made a procedure, to open the file dialog and load the file - I don't know how to "pass" it to devexpress, so the file actually loads to workbook.
Private Sub OpenXls()
Dim ofd As OpenFileDialog = New OpenFileDialog
ofd.DefaultExt = "xls"
ofd.FileName = "FILE"
ofd.InitialDirectory = "C:\ref_files"
ofd.Title = "Select file"
End Sub
As you have pointed out - using the dialog is not the right way.
After some googling I have find out that this should be a better way:
Dim workbook As New Workbook
workbook.LoadDocument("C:\ref_files\file.xls", DocumentFormat.xls)
I do not get any error, but the file is also not shown...
Do I have to display the document manually after loading?
If you're using openfiledialogue to open file then you must use command to load the specific file at Form.Load event.
The backslash char in ofd.InitialDirectory = "C:\ref_files"escapes the letter R to carrige return.
Change this line to ofd.InitialDirectory = "C:\\ref_files" (add another backslash).

VBA - How to set focus on OLE object window (IBM DOORS)

I'm writing a script in the VB to be used in excel, I'm using OLE to run a DXL script in DOORS. The DOORS script creates a popup window, which I'd like to give focus to when it's created.
Currently I have reference to the DOORS object, but I can't seem to find out how to set focus to the window. It might be that it's something that I have to do in the dxl, but I was wondering if there's a way to do this on the VB side of things.
So far I have:
Public Sub DoThing()
Const DxlFilepath As String = "C:\FilePath"
Dim DOORSObj As Object
'Double check the user wants to do this
vbCreateList = MsgBox("Current list will be lost. Please confirm to proceed? (Note: Parent folder must be selected in DOORS popup)", vbOKCancel, "Do thing")
If (vbCreateList = vbCancel) Then
Exit Sub
End If
'Get access to the DOORS application database
Set DOORSObj = CreateObject("DOORS.Application")
DOORSObj.result = "OK"
DOORSObj.runFile (DxlFilepath)
End Sub
Thanks in advance

How to get the path of selected folder in vb .net?

I have created a small application in vb .net to load all the files present inside the current folder where my application is running. I want to customize this application in such a manner that, when the user right click on any folder my application name also should appear in that menu. When the user click's that option, all the files present inside that corresponding folder should get listed.
I have achieved this partially. I have added my application to the right click menu item of all folders. But when I click my application name, all the files present in the parent directory is listed. I want to customize my coding to receive the path of the selected folder. So, how to do that?
There's a whole tutorial on MSDN: Verbs and File Associations
For example, the open verb normally launches a program to open a file. The command string typically looks as follows:
"My Program.exe" "%1"
You can get the parameters by the code below:
Public Sub Main(ByVal cmdArgs() As String)
If cmdArgs.Length > 0 Then
'Process the command.
'cmdArgs(0) is program name
'cmdArgs(1) is the path of your folder / file.
End If
End Sub
For Windows Forms, please see this .You'll need a function like below:
Public Sub Main(ByVal cmdArgs() As String)
'Process cmdArgs here (same as above)
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1)
End Sub

I have the file name open...Now how do I actually get the file itself to open?

I have a code that allows me to use an open file dialog to select a file. Once selected, the file path displays in Form3. What I'm trying to do from there is click Command_Button1 (Open) and physically open the file.
I can provide codes and JPEGs...but won't cloud this up until it is necessary :) I'm not using Common Dialog so the code is somewhat lengthy.
I looked online for a few hours yesterday and the closest I got was how to get it to open an Excel file...but this isn't Excel.
P.S. I'm new to VBA...so if this isn't as simple as a few lines of code and I'm missing the difficulty of it, please let me know. It seems like it should be a simple enough process...
Edit 1:
#mehow, Do you think it could be because the whole path name isn't displaying? I double clicked Open and nothing happened like you said
If you already know the path then..
Private Sub CommandButton1_Click()
dim myPath as String
myPath = "C:\files\file1.exe"
Dim shell As Object
Set shell = CreateObject("Shell.Application")
shell.Open myPath
End Sub

How to restrict to select multi Select of Files in Open FileDialog?

I have some task to select files in VB6 with the control "CommonDialog1".When the project is migrated this control is converted to openfile dialog.When some of the properties are not converted it is showing as commented.
This line was commented
'CommonDialog1.Flags = CommonDialog1.Flags Or &H80000 ' Dont ALLOWMULTISELECT
I want to know do we have any propery in VB.NET for Open File Dialog Control?
Just make a quick search, or use the help of IntelliSense if you're using Visual Studio.
Dim myOpenFile as New OpenFileDialog()
myOpenfile.Multiselect = False
Documentation