passing the file associated with an app into a Windows Forms app

  • Thread starter Thread starter Darren Mar-Elia \(MVP\)
  • Start date Start date
D

Darren Mar-Elia \(MVP\)

I have a Windows Forms app that let's a user type the path to a file into a
inputbox. What I'd like to be able to do is, if the user sets an association
between a particular file type and my application in Explorer, I'd like to
be able to pre-populate the inputbox on Form Load with the name of the file
they did the "Open With" in in Explorer. I don't see an obvious way to do
this.
This is .net 1.1

Thanks!


--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy
Check out http://www.gpoguy.com -- The Windows Group Policy Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related
And, the Windows Group Policy Guide is out from Microsoft Press!!! Check it
out at http://www.microsoft.com/mspress/books/8763.asp
GPOGUY Blog: http://blogs.dirteam.com/blogs/gpoguy
 
I tried that but it seems to only pass the full path of the executable
itself. What I'm after is the following. A user is in Explorer, they right
click on a file and choose Open With, and choose my app. When my app fires
up I'd like to pass the path of the file they right-clicked into the form.
That GetCommandLineArgs method doesn't seem to pass the right info.

Darren

--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy
Check out http://www.gpoguy.com -- The Windows Group Policy Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related
And, the Windows Group Policy Guide is out from Microsoft Press!!! Check it
out at http://www.microsoft.com/mspress/books/8763.asp
GPOGUY Blog: http://blogs.dirteam.com/blogs/gpoguy
 
Darren - The below code works every time for me. It returns the full path,
including the file name when a user opens a file with my program. I happen
to have a couple file extensions associated with my app.


FilePath = Microsoft.VisualBasic.Command().ToString
If FilePath = String.Empty Or FilePath = "" Then
'Not Opened From File
blnOpenFromSaved = False
Else
blnOpenFromSaved = True
NewFilePath = Replace(FilePath, """", "")
End If

MsgBox FilePath & VbCrLf & NewFilePath
 
Thanks Brian-
Unfortunately, I'm using C# and there doesn't *appear* to be an equivalent
method there. I must be missing it. Can't imagine this would be so hard.

Darren

--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy
Check out http://www.gpoguy.com -- The Windows Group Policy Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related
And, the Windows Group Policy Guide is out from Microsoft Press!!! Check it
out at http://www.microsoft.com/mspress/books/8763.asp
GPOGUY Blog: http://blogs.dirteam.com/blogs/gpoguy
 
Patrice-
I had tried that before and I wasn't getting the results I needed, but I
think I see why now--my mistake because of a debugging problem--it is
working with the GetComandLineArgs method.

Thanks to all who helped.

Darren
--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy
Check out http://www.gpoguy.com -- The Windows Group Policy Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related
And, the Windows Group Policy Guide is out from Microsoft Press!!! Check it
out at http://www.microsoft.com/mspress/books/8763.asp
GPOGUY Blog: http://blogs.dirteam.com/blogs/gpoguy
 
Back
Top