Basically, I'm building a website that allows user to upload file. From the front end (JavaScript), the user will browse a file, I can get the site to send POST data (the parameter "UploadInput" and it's value, which the value is the file) In the backend (C#), I want to make a copy of the file and save it in a specific path. Below is the way I did it.
var files = Request.Files; file[0].SaveAs("\temp\\" + file[0].FileName); The problem I ran into is that I got the error message saying index out of range. I tried Response.Write(files.Count) and it gives me 0 instead of 1. I'm wondering where I did wrong and how to fix it, or if there's a better way of doing it. Thanks!
Edit:
I am using HttpFox to debug. From HttpFox, I can see that under POST data, parameter is "UploadInput" and the value is "test.txt"
Edit 2: So I tried the way Marc provides, and I have a different problem. I am able to create a new file, however, the content is not copied over. I tried opening the new created file in notepad and all it says is "UploadInput = test.txt"
enctype="multipart/form-data"in the form?