can anyone give the solution of following error in Application Code Part:
startIndex cannot be larger than length of string.
Parameter name: startIndex
Code Part-//It's a files moving application...
Collapse | Copy Code
protected static void copyDirectory(string Src, string Dst)
{
string targetPath = Dst.Substring(0, Dst.LastIndexOf(@"\") + 1);
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
File.Copy(Src, Dst, true);
}
Collapse | Copy Code
static FileInfo[] ListDirectory(string path)
{
return (new DirectoryInfo(path)).GetFiles("*.*", System.IO.SearchOption.AllDirectories);
}
Collapse | Copy Code
private void button1_Browse(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
try
{
FileInfo[] fileList1 = ListDirectory(dir1);
FileInfo[] fileList2 = ListDirectory(dir2);
var files1 = (from f1 in fileList1 select f1.FullName);
var filediff = (from f1 in files1 select f1.Substring(dir1.Length)).Intersect(from f2 in files2 select f2.Substring(dir1.Length));
foreach (String s in filediff)
{
copyDirectory(dir2 + s, name2 + s);
}
Collapse | Copy Code
catch (IOException ex)
{
errlbl.Text = "*" + ex.ToString();
}
}
I've already taken the help of breakpoint but I am unable to solve it now I undwerlined it. plz resolve th error