Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How do I make a "Save" not "Save As"?

$
0
0

So what I mean by that is how do I make it so that I can save a file without having to go through the Save As prompt dialog.

private void saveAs(object sender, EventArgs e)
{
    if (saveAsDialog.ShowDialog() == DialogResult.OK)
    {
        Stream s = File.Open(saveAsDialog.FileName, FileMode.Create);
        StreamWriter sw = new StreamWriter(s);
        //saveAsDialog.Filter = "Text Files | *.txt"; // can only save as text files

        // writing block (long code)

        // closing
        sw.Close();
    }
}

Ok in this code this is using the Save As command, where a user must go through the dialog (overwriting a file won't give an error).

So how do I make a similar code as the normal Save method without having to go through the prompt?

Basically saved in the directory as the same name where it was last opened or saved as.



Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>