In my case the SaveFileDialog
will not write any file, but I want to use to specify the path for a command line app which will create the logfile on the same location as "saved" in the sf dialog.
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "*.txt";
string sfdname = saveFileDialog1.FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Path.GetFileName(sfd.FileName);
}
startInfo.Arguments = "--log=" + Path.GetFileName(sfd.FileName);
Here is the code: SaveFileDialog sfd = new SaveFileDialog(); sfd. Filter = "Xml files (*. xml)|*.
To save a file using the SaveFileDialog component. Display the Save File dialog box and call a method to save the file selected by the user. Use the SaveFileDialog component's OpenFile method to save the file. This method gives you a Stream object you can write to.
You can use
Path.GetFullPath(sfd.FileName);
Instead of
Path.GetFileName(sfd.FileName);
Complete version...
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "*.txt";
string sfdname = saveFileDialog1.FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Path.GetFullPath(sfd.FileName);
}
startInfo.Arguments = "--log=" + Path.GetFullPath(sfd.FileName);
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Image files | *.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
employee_dp.Image = Image.FromFile(openFileDialog1.FileName);
string path = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
string onlyFileName = System.IO.Path.GetFileName(openFileDialog1.FileName);
filepath = Path.GetFullPath(path).Replace(@"\", @"\\");
filepath = filepath + "\\\\" + onlyFileName;
MessageBox.Show(filepath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With