Link to home
Start Free TrialLog in
Avatar of urir10
urir10

asked on

Pass file from input type "File" to another page using Javascript

Hi All

I have a page that has some input fields and a file upload field (html Input Type="File", not asp FileUpload)
When the button is submitted it passes all the values to another page that writes it to the DB.

The only problem is to upload the file, how can i pass the file to the other page?
Avatar of bharathsharma
bharathsharma

you can get the value using below code
var FilePath;
FilePath = document.getElementById("FileUploadControlId").value
Avatar of urir10

ASKER

wouldnt that just give me the path thou?
Avatar of Dave Baldwin
What do you mean "pass the file to the other page"?
ASKER CERTIFIED SOLUTION
Avatar of scrathcyboy
scrathcyboy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since you have C# in your tags, it is probably ASP.Net (which has its own zone: https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/), and not Classic ASP.

> " (html Input Type="File", not asp FileUpload)"

Is there any difference in the HTML? Browsers can only do a file-upload with <input type="file" />, it does not matter how you create that on the server.

In order to have the browser upload a file, the form needs to have enctype="multipart/form-data", otherwise no file is uploaded. That creates a totally different request to the server, but in asp.net makes it easy for you, and you can retrieve the files from Request.Files