Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain file path of C# save dialog box

Tags:

c#

dialog

I've got a save dialog box which pops up when i press a button. However i dont want to save a file at that point, i want to take the name and place it in the text box next to the button, for the name to be used later.

Can anybody tell me how to obtain the file path from the save dialog box to use it later?

like image 933
Mister Dev Avatar asked Oct 07 '08 20:10

Mister Dev


People also ask

How do I get a file path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

What is absolute path in C?

For example, if your prompt was "C:\Windows>" and you wanted to know the absolute path of a calc.exe file in that directory, its absolute path is "c:\windows\calc.exe". In other words, the absolute path is the full directory path plus the file name.

How do I find the path of a text file?

Click at the end of the box that contains the file name. It's just above the list of files inside the folder, and just below the icons. This highlights the full path to the file. To copy the path, press Ctrl + C .

What is the path of a file?

A file path describes the location of a file in a web site's folder structure. File paths are used when linking to external files, like: Web pages. Images. Style sheets.


2 Answers

Here is a sample code I just wrote very fast... instead of Console.Write you can simply store the path in a variable and use it later.

SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 
saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments); 
saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files (*.*)|*.*" ; 
saveFileDialog1.FilterIndex = 1; 

if(saveFileDialog1.ShowDialog() == DialogResult.OK) 
{ 
    Console.WriteLine(saveFileDialog1.FileName);//Do what you want here
} 
like image 103
Patrick Desjardins Avatar answered Oct 09 '22 03:10

Patrick Desjardins


Addressing the textbox...

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
    this.textBox1.Text = saveFileDialog.FileName;
}
like image 32
Inisheer Avatar answered Oct 09 '22 05:10

Inisheer