0

I want to save my backup file in specific folder. currently I'm using a saveFileDialog box to give path and file name on a button click. But I want to create this backup by giving name as (DateTime.Today.Date.ToShortDateString()) and save this in "D:\Database" directly on button click. and don't want to use saveFileDialog box. I'm using this code:

SqlCommand cmd = new SqlCommand("USE MASTER BACKUP DATABASE plproject TO DISK = '" + saveFileDialog1.FileName + "'", connectionsql);
Arpit
  • 12,767
  • 3
  • 27
  • 40
Sonu_Orai
  • 377
  • 2
  • 7
  • 17
  • what you want, please clear – vikas Oct 06 '13 at 13:54
  • just got it, but what is the issue, if you are using `DateTime.Today.Date.ToShortDateString()` – vikas Oct 06 '13 at 13:55
  • currently I give path by saveFileDialog box but if I don't use saveFileDialog box, I don't know how can give the path and file name – Sonu_Orai Oct 06 '13 at 13:58
  • I am not sure what you are looking here, you can directly replace `saveFileDialog1.FileName` with `DateTime.Today.Date.ToShortDateString()` – vikas Oct 06 '13 at 14:09
  • So where can I find that file? – Sonu_Orai Oct 06 '13 at 14:43
  • you can replace your folder path here and can use - [your folder path] `SqlCommand cmd = new SqlCommand("USE MASTER BACKUP DATABASE plproject TO DISK = '[your folder path]" + DateTime.Today.Date.ToShortDateString() + "'", connectionsql);` – vikas Oct 07 '13 at 12:08

1 Answers1

0

I guess you are looking for this

public static void WriteAllText(
    string path,
    string contents
)

File.WriteAllText("D:\\DataBase\\"+DateTime.Today.Date.ToShortDateString(),YOURDATASTRING);

Note: It will overwrite any file with same name.

There are many other useful methods available in FILE class. You can check which suits you best.

EDIT 1

Try this

string fileName="D:\\Backup\\"+DateTime.Today.Date.ToShortDateString();
SqlCommand cmd = new SqlCommand("USE MASTER BACKUP DATABASE plproject TO DISK = '" + fileName + "'", connectionsql);
Arpit
  • 12,767
  • 3
  • 27
  • 40