开发者

how to get file directory when open with or send to event?

How do I get a file's directory when open with or send to ev开发者_高级运维ent happens? I want it like media player, the application can get the file name & path when the user runs it with Open With.


The filename will be pased on the command line to your application, so you can access it by either

Module MainModule

  Sub Main(cmdArgs As String())

    Dim fileName as string = cmdArgs(0)

  End Sub

End Module

For a console application, or by

 Dim args As String() = Environment.GetCommandLineArgs()
 Dim fileName As String = args(1)

For a GUI application.

Note that when using Environment.GetCommandLineArgs(), the first element in the array will be the full path to your executable, so you need to access the second element to get the file name. In the first example, cmdArgs will only contain the file name parameter.

To get the directory name containing the file, you can use

Dim path as String = System.IO.Path.GetDirectoryName(fileName)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜