0

Here is a snippet of my code:

MessageBox.Show(String.Format("The Export will be avilable in {0}", folderPath)

folderPath here shows the path of my output file. So I want the messsage box here to show as

"The Export will be available in C:\Test."

I should be able to navigate to C:\Test by clicking on it. Help?

Allan
  • 15
  • 5

2 Answers2

1

You can try this:

string filePath = @"C:/Test/testFile.txt";
string directory =  Path.GetDirectoryName(filePath);
if (MessageBox.Show(String.Format("The Export will be avilable in {0}. Open Folder?",
   directory), "Open Directory", MessageBoxButtons.YesNo,
   MessageBoxIcon.Information) == DialogResult.Yes)
{
    System.Diagnostics.Process.Start(directory);
}
daniell89
  • 1,832
  • 16
  • 28
  • Although I would go for a custom dialog form, this is a quick and easy solution. Nice – Pikoh Apr 11 '17 at 09:45
  • Thanks for your answer. Do you use name spaces / references assuming custom dialog form does not come along with the VS 2012 package? – Allan Apr 11 '17 at 10:37
  • Also, this opens up only the root directory and not the folder in which the file is created. Any idea? @daniell89 – Allan Apr 11 '17 at 10:38
  • Never mind, System.Diagnostics.Process.Start("explorer.exe", folderPath) worked. Thanks :) – Allan Apr 11 '17 at 10:49
0

You cannot do that with messagebox.

What I recommend is for you to create your own form and then show it using

yourCustomForm.ShowDialog()

It is very easy to do and works perfectly, is flexible and you can customize as you wish. I use this approach myself and seen this used even in big projects

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39
  • Thanks for this. Do you use name spaces / references assuming this does not come along with the VS 2012 package? – Allan Apr 11 '17 at 09:41
  • Yes I use namespaces. I have switched to VS 2015 Community now and later will update to VS 2017. – Kristi Jorgji Apr 11 '17 at 10:43