Quote:
The file is selected by the user; so it necessarily exists when I had done my test (I selected it myself) .. FileUpload1.FileName.ToLower ();
NB: FileUpload1.FileName
refers to the path - or often just the name - of the file
on the user's computer. Your code is running
on your server. Code running on the server has no access to files stored on the user's computer.
Your code
appears to work when you run it locally. But that's only because, in that specific case, the server and client are the same computer. When you deploy your code to a real server, your code cannot access the files stored on the client.
As an analogy, if I told you my scissors are in the third drawer down in the kitchen, that would be correct for my house. But if you went to the third drawer down in your kitchen, you probably wouldn't find any scissors. And even if you did, they wouldn't be the same scissors I was referring to.
When the user uploads a file, you have to either save that file to a folder on your server, or process the
InputStream
in-memory. You can't simply open the
FileName
and expect it to work.