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";
} 

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.