Hai guys, Hope you are all doing fine. Now I am working in file uploading process. process of uploading the file from the system is working good but my problem is I want to move the uploaded file from that folder to another folder I tried few samples but all the samples are creating a same error "Could not find a part of the path 'D:\CMS\app\views\UploadDocumets\geography_ssc_capsule_7.pdf'." the code that I use is given below, please help me to solve this problem friends.
string fileName = Filenames; (name of the file that I uploaded)
string sourcePath = @"D:\CMS\app\views\UploadDocumets";
string targetPath = @"D:\Projects\aanthony_23Mar2013\UpLoadDocuments";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
else
{
}
Thank you very much
Ankur JainPosted Aug 25, 2014, 12:58 AM
your code works well, There can be security issues while saving/uploading file,But i think your error clearly states that while uploading file,the directory where you want to upload file is not present.Or it is not mapped to server. so you can follow following steps.