Vasu Gadhiya

Vasu Gadhiya

  • NA
  • 429
  • 101.3k

can't copy all files from one directory to other directory.

Sep 10 2013 12:39 AM
I Write Code For create a new folder and copy all photo from other folder to new folder.

-----------------------------------------------
string path = Server.MapPath(@"photos\test2");

string sourcepath = Server.MapPath(@"photos\test");

System.IO.Directory.CreateDirectory(path);
string[] files = System.IO.Directory.GetFiles(sourcepath);

 foreach (string s in files)
 {
                    
                    string filename = System.IO.Path.GetFileName(s);
                    string destfile = System.IO.Path.Combine(sourcepath, filename);

                    System.IO.File.Copy(s, destfile, true);

}
-----------------------------------------------

But when its run its occur error

Server Error in '/' Application.

The process cannot access the file 'I:\vasu\Project\test\error.png' because it is being used by another process.

Line 48:                 System.IO.File.Copy(s, destfile, true);



Answers (2)