Finally I got the solution,I would like to share this issue,so that it may help somebody.Following is my piece of code
private void MoveFiles()
{
try
{
string Tranfiles, ProcessedFiles;
//Tranfiles = Server.MapPath(@"~\godurian\sth100\transfiles\" + Filename);
Tranfiles = Server.MapPath(@"~\transfiles\" + Filename);
if (File.Exists(Server.MapPath(@"~\transfiles\" + Filename)))
{
//Need to mention any file,so that to overwrite this newly created with the actual file,other wise will get 2 errors like
//1)Cannot create a file when that file already exists
//2)The path....is a folder not a file.
//ProcessedFiles = Server.MapPath(@"~\ProcessedFiles"); //Wrong
ProcessedFiles = Server.MapPath(@"~\ProcessedFiles\"+Filename);//Need to mention any file in dest folder,even though it doesnt contain this file.
//Need to move or overwrite the new file with actual file.
File.Move(Tranfiles, ProcessedFiles);
File.Delete(Server.MapPath(@"~\transfiles\" + Filename));
}
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
The main crux here is,instead of moving files directly to dest folder,we should mention any file in dest folder and need to overwrite that file.Thats it.