Question

In my application I have my own custom filetype. I set it up so my application opens up files of this type when they are clicked outside of my application. Now my question is: How can I get the SafeFileName of the file being opened? I know that that variable S is my filename, although I want to get just the actual files name without the location.

    If (Environment.GetCommandLineArgs.Length > 1) Then

      Dim s As String = Environment.GetCommandLineArgs(1)

     ' Open file s

    End If

I know if I was using the filename it would be OpenFileDialog.SafeFileName, and that would give me test123.txt instead of C:\Files\Test123.txt

How could I do the same in this situation.

Was it helpful?

Solution

It depends on what the string that is being returned looks like and if it is a valid path, if it is like your example you can use Path.GetFileName Method of the System.IO Namespace.

Dim s As String = "C:\Files\Test123.txt"
Dim myFile As String = Path.GetFileName(s)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top