gabe3vino
gabe3vino

Reputation: 333

How to identify a string as filepath and open in file explorer when clicked?

I am relatively new to C#/Visual Studio 2015 application development, coming from Android. I am writing a chat application that also allows users to send files to each other. The file transfer functionality is in place; the file gets downloaded to a pre-set folder when received, and the file-path of that file is then shown in the chat box to the recipient. However, that file path is shown as though it were regular text.

How do I make it such that said file-path (and/or urls, ideally) appear as a clickable hyperlinks, that then open said file?

Any help or resources to be pointed to would be most appreciated!

Upvotes: 0

Views: 549

Answers (2)

Husni Salax
Husni Salax

Reputation: 2020

Here we go:

You should use Uri class to build your url from string:

string filePath = "C:\\example.txt";
Uri uri = new Uri(filePath);
return uri.AbsoluteUri;

Hope it helps;)

Upvotes: 0

Ruben Aguilar
Ruben Aguilar

Reputation: 1235

If you create a linkLabel object to show the path, you can add a callback to the event LinkClicked and open a file explorer:

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        Process.Start("C:/");
    }

Upvotes: 1

Related Questions