C
C#3w ago
Rafcord

✅ How can I get the path where function saves files?

How can I get the path where this function saves files?
c#
public void SaveMaze(SaveFileDialog saveFileDialog, Image image)
{
string filePath = name + myImageId + ".jpg";
saveFileDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp";
saveFileDialog.Title = "Save an Image File";
saveFileDialog.FileName = filePath;
saveFileDialog.ShowDialog();

if (saveFileDialog.FileName != "")
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog.OpenFile();

image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();
}

myImageId++;
}
c#
public void SaveMaze(SaveFileDialog saveFileDialog, Image image)
{
string filePath = name + myImageId + ".jpg";
saveFileDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp";
saveFileDialog.Title = "Save an Image File";
saveFileDialog.FileName = filePath;
saveFileDialog.ShowDialog();

if (saveFileDialog.FileName != "")
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog.OpenFile();

image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();
}

myImageId++;
}
I don't set it at any point, but I use WinForms.
4 Replies
Gene
Gene3w ago
According to the docs you can just read FileNames after ShowDialog() which contains all user selected files with their full path. See https://learn.microsoft.com/de-de/dotnet/api/system.windows.forms.filedialog.filenames?view=windowsdesktop-9.0#system-windows-forms-filedialog-filenames
FileDialog.FileNames Eigenschaft (System.Windows.Forms)
Ruft die Dateinamen aller im Dialogfeld ausgewählten Dateien ab.
canton7
canton73w ago
Yep, that's what I've always done Looks like OpenFile just accesses FileNames[0]: https://source.dot.net/#System.Windows.Forms/System/Windows/Forms/Dialogs/CommonDialogs/SaveFileDialog.cs,75
MODiX
MODiX3w ago
mtreit
Directory.CurrentDirectory will tell you.
Quoted by
<@1102729783969861782> from #chat (click here)
React with ❌ to remove this embed.
leowest
leowest3w ago
he was already replied in #chat so closing this...

Did you find this page helpful?