65.9K
CodeProject is changing. Read more.
Home

Could not find a part of the path while doing a File Copy

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.89/5 (4 votes)

Mar 2, 2012

CPOL
viewsIcon

27658

If at all possible, never give your code the opportunity to fail. If there's any possibility at all that you can prevent an error condition from being raised, do it. try{ if (!string.IsNullOrEmpty(FileName)) { string newPath = System.IO.Path.Combine(FilePath,...

If at all possible, never give your code the opportunity to fail. If there's any possibility at all that you can prevent an error condition from being raised, do it.
try
{
    if (!string.IsNullOrEmpty(FileName))
    {
        string newPath = System.IO.Path.Combine(FilePath, FileName); 
        if (File.Exists(Path) && Path.ToLower() != newPath.ToLower())
        {
            File.Copy(Path, newPath, true);
        }
    }
}
catch (Exception ex)
{
    // handle the exception as desired
}