Answered by:
SaveFileDialog Trouble

Question
-
I managed to figure out how to use SaveFileDialog. However when I go through the whole process (actually using the GUI app) it doesn't actually save anything.
Click Save => It Works
'Save Dialog' Opens => It Works
My extensions Show up => It Works
Allows me to enter a name => It Works
Click 'Save' = .... Nothing Happens
- Moved by lucy-liu Monday, February 28, 2011 3:43 AM it is not related to vc (From:Visual C++ Express Edition)
Friday, February 25, 2011 2:44 AM
Answers
-
>how to make the Save button (on the saveFileDialog)
>work, still has me confused.
You make it work by clicking on it. 8=}
Are you still having issues with this, or have you solved it?
In a nutshell, the code you have posted will create and open
a Save File dialog. Control will return to your code when that
dialog is closed. If it was closed by clicking on the Save
button or by double-clicking on a filename in the list, then
the file specified in the "File name:" dropdown box will be
Opened. If it was cancelled (! DialogResult::OK) then the file
won't be opened.
An alternative to using OpenFile() is to use the property
saveFileDialog1->FileName and code the file handling using
something other than a Stream object. e.g. -
String^ Sfnm = saveFileDialog1->FileName;
// Create a file to write to.
StreamWriter^ sw = File::CreateText(Sfnm);
try
{
sw->WriteLine("Hello ");
sw->WriteLine("Fat");
sw->WriteLine("Guy!");
}
finally
{
if (sw) delete (IDisposable^)(sw);
}
See:
File Class
http://msdn.microsoft.com/en-us/library/system.io.file(v=VS.90).aspx
- Wayne
- Proposed as answer by Mike Dos Zhang Wednesday, March 2, 2011 7:21 PM
- Marked as answer by Mike Dos Zhang Sunday, March 6, 2011 7:33 PM
Saturday, February 26, 2011 7:49 PM -
Hi thatFatGuy.cpp,
How to: Save Files Using the SaveFileDialog Component
The SaveFileDialog component allows users to browse the file system and select files to be saved. The dialog box returns the path and name of the file the user has selected in the dialog box. However, you must write the code to actually write the files to disk.
If there's any concern, please feel free to let me know.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Mike Dos Zhang Wednesday, March 2, 2011 7:22 PM
- Marked as answer by Mike Dos Zhang Sunday, March 6, 2011 7:32 PM
Wednesday, March 2, 2011 7:21 PM
All replies
-
>I managed to figure out how to use SaveFileDialog.
Could you be a little more specific?
Which SaveFileDialog are you using?
>it doesn't actually save anything.
>Click 'Save' = .... Nothing Happens
If using Windows Forms, note the quote below from:
SaveFileDialog Component Overview (Windows Forms)
http://msdn.microsoft.com/en-us/library/es77fa37.aspx
"Be aware, however, that when using the SaveFileDialog
component, you must write your own file-saving logic."
Did you do that?
- Wayne- Proposed as answer by Mike Dos Zhang Wednesday, March 2, 2011 7:21 PM
Friday, February 25, 2011 5:01 AM -
No, I didn't. So just make something like?:
ofstream myfile; myfile.open(/*Don't know how to tell it where to save by using the saveFileDialog*/); myfile << bodystr; myfile.Close();
If so, How to I get the directory->Chosen by the saveFileDialog?
Also, if I have to write my own code, How to I program it to:
if(user clicks save button) { myfile routine }
//-----------------------------------
BTW where I said "I figured out how to use the saveFileDialog", I meant that it wasn't as obvious to figure out as I though I had to assign a toolStripMenuButton to Show the Dialog. It was just saying that I got past step 1 (of making the dialog come on the screen), now I just need to make the 'Save Button' (in the saveFileDialog) return a directory so 'myfile' knows where to open/save the file.
I really hope this all makes sense, LA skills have never been my strong suit.
Friday, February 25, 2011 9:39 PM -
I may found something helpful from your link.
Only part of this code is needed because of the property settings that VS offers. Also I still don't know how to tie all in with the SAVE button illustrated below:
http://i869.photobucket.com/albums/ab255/michaeloohra/untitled-13.jpg
============
But the code for the button that opens the savedialog
private: void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { Stream^ myStream; SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog; if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK ) { if ( (myStream = saveFileDialog1->OpenFile()) != nullptr ) { // Code to write the stream goes here. //Though I'm still not sure what to put, unless myfile.open();
Then again how to make the Save button (on the saveFileDialog) work, still has me confused.
myStream->Close(); } } }Friday, February 25, 2011 10:03 PM -
>how to make the Save button (on the saveFileDialog)
>work, still has me confused.
You make it work by clicking on it. 8=}
Are you still having issues with this, or have you solved it?
In a nutshell, the code you have posted will create and open
a Save File dialog. Control will return to your code when that
dialog is closed. If it was closed by clicking on the Save
button or by double-clicking on a filename in the list, then
the file specified in the "File name:" dropdown box will be
Opened. If it was cancelled (! DialogResult::OK) then the file
won't be opened.
An alternative to using OpenFile() is to use the property
saveFileDialog1->FileName and code the file handling using
something other than a Stream object. e.g. -
String^ Sfnm = saveFileDialog1->FileName;
// Create a file to write to.
StreamWriter^ sw = File::CreateText(Sfnm);
try
{
sw->WriteLine("Hello ");
sw->WriteLine("Fat");
sw->WriteLine("Guy!");
}
finally
{
if (sw) delete (IDisposable^)(sw);
}
See:
File Class
http://msdn.microsoft.com/en-us/library/system.io.file(v=VS.90).aspx
- Wayne
- Proposed as answer by Mike Dos Zhang Wednesday, March 2, 2011 7:21 PM
- Marked as answer by Mike Dos Zhang Sunday, March 6, 2011 7:33 PM
Saturday, February 26, 2011 7:49 PM -
Hi thatFatGuy,
I am moving this thread from “Visual C++ Express Edition" forum to the “Windows Forms General” forum.,
since the issue is related to Windows Forms .There are more experts in the “Windows Forms General" forum.Thank you for your understanding,
Best regards,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, February 28, 2011 3:42 AM -
Hi thatFatGuy.cpp,
How to: Save Files Using the SaveFileDialog Component
The SaveFileDialog component allows users to browse the file system and select files to be saved. The dialog box returns the path and name of the file the user has selected in the dialog box. However, you must write the code to actually write the files to disk.
If there's any concern, please feel free to let me know.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Mike Dos Zhang Wednesday, March 2, 2011 7:22 PM
- Marked as answer by Mike Dos Zhang Sunday, March 6, 2011 7:32 PM
Wednesday, March 2, 2011 7:21 PM