0

I am working on Client side application.. need to upload a file.How could i save file on server using jquery as i am only sending the path of file through ajax and need to copy same file on server as on folder....Below is my code ..How do i copy that file to server??? Having Error on this. /// UploadFile is a Folder Name on which i have to save/copy the file. /// file is a string variable which stores only path of uploaded file.

string FileName = System.IO.Path.GetFileName(file);
string Extension = System.IO.Path.GetExtension(file);
string SaveLocation = HttpContext.Current.Server.MapPath("UploadFile") + "\\";
System.IO.File.Copy(file,SaveLocation,true);
if (System.IO.File.Exists(SaveLocation))
{
    System.IO.File.Delete(SaveLocation);
}
//fileupload.SaveAs(FilePath);

System.IO.FileInfo fi = new System.IO.FileInfo(SaveLocation);
if (!fi.Exists)
{
    msg = "File " + SaveLocation + " Does Not Exists";
} 
Christos
  • 53,228
  • 8
  • 76
  • 108
techV
  • 935
  • 3
  • 23
  • 41

1 Answers1

1

The server cannot access files on client machines, that is not how web browsers/servers work-- the only way to get a file to the server is by sending it over the wire via some form of upload control.

To do this via jQuery, there are several plugins and options, as discussed in How can I upload files asynchronously with jQuery?

Community
  • 1
  • 1
DanS
  • 792
  • 5
  • 10