2
Answers

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

Vasu Gadhiya

Vasu Gadhiya

11y
1.3k
1
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)