Below is my code

SW = File.CreateText("D:\\PNB\\" + System.DateTime.Now.Date.ToString("ddMMyyyy") + "_" + bn + ".txt");

Here the file is create in d:/Pnb which is hard coded
But i want to save it where the user want it to
Can any one Help me for the same

I am creating the file using Stream Writer
Stream Writer sw;
sw = file.createfile(...)
As this is creating file, can i create the file to the location specified by

Can any one help me for the same.

Try this one:

string path = @"C:\1\testFile.txt";
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                using (TextWriter tw = new StreamWriter(fs))
                    //use tw variable to do writing!

Something like:

string chosenFilePath = System.Shell.saveFileDialog("", "*.*");
   string chosenDirectoryPath = Path.GetDirectoryName(chosenFilePath);
   string destinationPath = Path.Combine(chosenDirectoryPath, System.DateTime.Now.Date.ToString("ddMMyyyy") + "_" + bn + ".txt");
   SW = File.CreateText(destinationPath);

Sorry I don't have time to test the code above but it can be something like that :)

Also... I guess you should look for a directory selector instead of a file selector like:

Edited 5 Years Ago by RobbertKeesing: n/a

This article has been dead for over six months. Start a new discussion instead.