Reputation: 1550
I want to save images to my project folder from openfiledialog result . I don't get foler path to save . How do I get folder path ? How do I save that ? Please Help me.
Upvotes: 1
Views: 8752
Reputation: 765
Hello thinzar,
private void button2_Click(object sender, EventArgs e)
{
Bitmap myBitmap = new Bitmap();
this.saveFileDialog1.FileName = Application.ExecutablePath;
if (this.saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
myBitmap.Save(this.saveFileDialog1.FileName);
}
}
Bye
Upvotes: 2
Reputation: 34489
Something alone these lines
Bitmap myImage = new Bitmap();
// draw on the image
SaveFileDialog sfd = new SaveFileDialog ();
if(sfd.ShowDialog() == DialogResult.OK)
{
myImage.Save(sfd.FileName);
}
Upvotes: 1
Reputation: 9936
The System.Windows.Forms.FolderBrowserDialog allows the user to select a folder. Maybe that would be a better option?
Upvotes: 1
Reputation: 1611
I guess you're opening a file elsewhere and then using the results to later save stuff into the directory you opened from?
DialogResult result = OpenFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string directoryName = Path.GetDirectoryName(OpenFileDialog1.FileName);
// directoryName now contains the path
}
Upvotes: 0
Reputation: 19790
FileDialog.FileName gives the full path to the file. And btw it is probably easier to use the SaveFileDialog because you want to save something, not open.
Upvotes: 3