[英]how to save any file in specific folder in c# programatically
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
. 当前,我正在使用saveFileDialog
框来button click
提供path
和文件名。 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. 但是我想通过提供名称为(DateTime.Today.Date.ToShortDateString())
来创建此备份,然后单击button
直接将其保存在"D:\\Database"
。 and don't want to use saveFileDialog
box. 不想使用saveFileDialog
框。 I'm using this code: 我正在使用此代码:
SqlCommand cmd = new SqlCommand("USE MASTER BACKUP DATABASE plproject TO DISK = '" + saveFileDialog1.FileName + "'", connectionsql);
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. FILE类中还有许多其他有用的方法。 You can check which suits you best. 您可以检查哪个最适合您。
EDIT 1 编辑1
Try this 尝试这个
string fileName="D:\\Backup\\"+DateTime.Today.Date.ToShortDateString();
SqlCommand cmd = new SqlCommand("USE MASTER BACKUP DATABASE plproject TO DISK = '" + fileName + "'", connectionsql);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.