<summary>
Data backup
</summary>
///
public bool DataBackup (string getpath)
{
Try
{
SqlConnection con = new SqlConnection (); Using code to connect to a database
Con. ConnectionString = configurationsettings.appsettings["DataBase"]. ToString ();
Con. Open ();
SqlCommand com = new SqlCommand ();
Com.commandtext = "BACKUP DATABASE Name to DISK = '" + GetPath + "'";
Com. Connection = con; Connection
Com. ExecuteNonQuery ();
int i = com. ExecuteNonQuery ();
if (COM. ExecuteNonQuery () ==-1)
//{
Showexclamation ("Data has been successfully backed up! ");
//}
Con. Close ();
Con. Dispose ();
return true;
}
catch (Exception k)
{
MessageBox.Show (K.message);
return false;
}
}
if (! System.IO.Directory.Exists ("d:\\ backup File"))
{
System.IO.Directory.CreateDirectory ("d:\\ backup file");
}
string path = @ "d:\ backup file \" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ". Bak";
This.dqlib.DataBackup (path);
DirectoryInfo BaseDir = new DirectoryInfo ("d:\\ backup file");
Gets all the files under the specified folder.
If you need to get files in a particular format, such as. html, you can write Basedir.getfiles ("*.html");
fileinfo[] files = basedir.getfiles ();
Define a file name string
String fileNames = String. Empty;
if (Files. Length > 10)
{
for (int i = 0; i < files. Length; i++)
{
Get each file name and log it to the string fileNames
If you need to get the full path name of the file, Files[i]. FullName;
if (Datetime.compare (files[i). CreationTime, DateTime.Now.AddDays ( -10)) < 0)
{
Files[i]. Delete ();
}
}
}
Automatically backs up the SQL database and deletes the backup file before the specified date