Question File not found using LinkClickedEvent from a richtext box with leading underscore in filename

bigsagal

New member
Joined
Dec 17, 2023
Messages
1
Programming Experience
10+
C#:
private void Link_Clicked (object sender, System.Windows.Forms.LinkClickedEventArgs e) {
    try {
        System.Diagnostics.Process.Start(e.LinkText);
    } catch {
        MessageBox.Show("The following could not be found:\n\n"+e.LinkText,"Not found");
    }
I use the above code to link to websites or to local files on my pc from within a richtextbox. However, the link fails if the filename begins with an underscore. For example, file://c:\folder\file_name.txt works but file://c:\folder\_file_name.txt won't. Bug? Please don't tell me to avoid using leading underscores because my wife does it everywhere.
 
Last edited by a moderator:
If you catch the actual exception instead of assuming that the exception is "file not found", the exception's message might actually show why the Process.Start() failed.
 

Latest posts

Back
Top Bottom