am so confused...wen you use save dialog....you only get the dialog and wen i say save, it saves....my problem is, wen you go back to the folder to check the file saved....nothin is there....i want to know how you can save a file to a certain folder and wen saved you can go back to that folder and find the file there........VERY URGENT

Recommended Answers

All 11 Replies

The SaveFileDialog does not save anything. It is used to get the filename and path of where the user wants you to save the data.

You must test the return value from the ShowDialog method.
If it is DialogResult.OK you then save the data to a file using the FileName property from the SaveFileDialog.

SaveFileDialog only gets the path where the user wants to save, as nick.crane said.

You can then use that path to save the file. For instance, if you are using an image then you will have to use SomeImage.Save(SaveFileDialog.FileName) to save the image in the path specified by the user (using the SaveFileDialog).

Here's an example:

private void SaveBtn_Click(object sender, EventArgs e)
{
   DialogResult result = SaveFileDialog.ShowDialog();

   // Make sure the user has clicked "OK" or "Save"
   // and didn't cancel the dialog
   if(result == DialogResult.OK)
   {
      // for image
      SomeImage.Save(DialogResult.FileName);
   }
}

Thanks

wat if its a filled form i want to save....how do you save details of a form

Saving (or persisting) data can mean many things depending upon what you want to save and where you want to save it.
The data could be stored in a DB, saved as a text file or a binary file.
The simplest of these is to save to a text file. This is helpful if you are just starting out with persistance as you can examine the saved file with Notepad.

Look at the help for
System.IO.File.CreateText
System.IO.StreamWriter
System.IO.File.OpenText
System.IO.StreamReader

depends on how you want to save the file. If you are saving to store data that you can access when you open the program after closing it use

streamwriter
and
streamreader

I am using that alot right now on a program I am working on. I would be more then happy to help you with that if you need it (I am really good at using these as my one file I save to outputs multiple data for one thing so I needed a unique way to read it in)

i finally was able to save contents of a form to a database...sql server databases.Thanks for all your help.totally appreciate

That's good to hear (I still need to learn how to use databases with C#)

i will try give a tutorial soon....have a great time coding.

Btw if it all worekd out for you good to hear (sorry going over old posts) but if you are still having trouble I have finally learned how to use an excel file as a DB (took me forever to understand and I am still learning it but I got the basics down), so i can definitly help with that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.