My file can be save properly in the backup found. I would like to rename the backup file name,something like "DEPOT-Pub_Sub_Combined (wo CardHolder)" + textbox1.text + ".sql"
. For example the textbox1
value is 1,So it will be DEPOT-Pub_Sub_Combined (wo CardHolder) 1.sql
and when I run the program 2nd time, It will create copy of the original backup and update that file and save It's name as whatever the textbox.text value is
. How can this be done? what should i do?
private void modifySQLFile()
{
CopyFile();
string destFileName = @"backup\DEPOT-Pub_Sub_Combined (wo CardHolder).sql" ;
string[] fileTexts = File.ReadAllLines(@"backup\DEPOT-Pub_Sub_Combined (wo CardHolder).sql");
int counter = 0;
//File processing
foreach (string line in fileTexts)
{
//only process non-comments line
if (line.StartsWith("--") == false)
{
//replace instances of server name
if (line.Contains(SERVERNAME) == true)
{
fileTexts[counter] = fileTexts[counter].Replace(SERVERNAME, textBox1.Text);
}
if (line.Contains(ACCESSID) == true)
{
fileTexts[counter] = fileTexts[counter].Replace(ACCESSID, textBox2.Text);
}
if(line.Contains(NETWORKID) == true)
{
fileTexts[counter] = fileTexts[counter].Replace(NETWORKID, textBox2.Text);
}
}
counter++;
}
//update file
File.WriteAllLines(destFileName, fileTexts);
File.Move(destFileName, "DEPOT-Pub_Sub_Combined (wo CardHolder)" + textBox1.Text + ".sql");
MessageBox.Show("Completed!");
}
private void CopyFile()
{
string targetPath = @"backup";
string destFile = Path.Combine(targetPath, fileName);
if(!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
File.Copy(fileName, destFile, true);
}