C
Carlo Goretti
Guest
Hey!
Im trying to make an search and replace in a SQL document but it just says that "Cannot access the file because it being used by another process..".. Do someone knows what im doing wrong?
string KundLänk = StandardSökvägTxt.Text.Substring(0, StandardSökvägTxt.Text.LastIndexOf(@"\") + 1);
string KundMapp = KundLänk + KundNamnTxt.Text;
Directory.CreateDirectory(KundMapp);
//string fileToCopy = StandardSökvägTxt.Text + @"\*.sql";
//File.Copy(fileToCopy, KundMapp + Path.GetFileName(fileToCopy));
//string picturesFile = @"D:\pictures";
//string destFile = @"C:\Temp\tempFolder\";
foreach (string newPath in Directory.GetFiles(StandardSökvägTxt.Text, "*.*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(StandardSökvägTxt.Text, KundMapp), true);
}
//client.CheckOut(new Uri("https://svn.momentum.se/svn/PMSkript/Konvertering PM4 - PM5/PM4_Grund_Konvertering/Standard_Uppsättning"), KundMapp);
try
{
files = Directory.GetFiles(KundMapp, "*.sql", SearchOption.AllDirectories);
for (int i = 1; i < files.Count(); i++)
{
StreamReader reading = File.OpenText(files);
string str;
while ((str = reading.ReadLine()) != null)
{
if (str.Contains(HittaTxt.Text))
{
string test = str.Replace(HittaTxt.Text, ErsättTxt.Text);
File.WriteAllText(files, test);
}
}
}
}
catch(IOException exception)
{
MessageBox.Show(exception.ToString());
}
thanks for all answer!
Continue reading...
Im trying to make an search and replace in a SQL document but it just says that "Cannot access the file because it being used by another process..".. Do someone knows what im doing wrong?
string KundLänk = StandardSökvägTxt.Text.Substring(0, StandardSökvägTxt.Text.LastIndexOf(@"\") + 1);
string KundMapp = KundLänk + KundNamnTxt.Text;
Directory.CreateDirectory(KundMapp);
//string fileToCopy = StandardSökvägTxt.Text + @"\*.sql";
//File.Copy(fileToCopy, KundMapp + Path.GetFileName(fileToCopy));
//string picturesFile = @"D:\pictures";
//string destFile = @"C:\Temp\tempFolder\";
foreach (string newPath in Directory.GetFiles(StandardSökvägTxt.Text, "*.*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(StandardSökvägTxt.Text, KundMapp), true);
}
//client.CheckOut(new Uri("https://svn.momentum.se/svn/PMSkript/Konvertering PM4 - PM5/PM4_Grund_Konvertering/Standard_Uppsättning"), KundMapp);
try
{
files = Directory.GetFiles(KundMapp, "*.sql", SearchOption.AllDirectories);
for (int i = 1; i < files.Count(); i++)
{
StreamReader reading = File.OpenText(files);
string str;
while ((str = reading.ReadLine()) != null)
{
if (str.Contains(HittaTxt.Text))
{
string test = str.Replace(HittaTxt.Text, ErsättTxt.Text);
File.WriteAllText(files, test);
}
}
}
}
catch(IOException exception)
{
MessageBox.Show(exception.ToString());
}
thanks for all answer!
Continue reading...