For reasons beyond this question, I cannot have a form on this page with a runat="server"
attribute.
How do I go about accessing an uploaded file uploaded using a regular <input type="file"...
?
This question touches on the issue, (using an <input type="file"
rather than an <asp:FileUpload
), however they still both runat=server.
The types of things I would like to be able to acheive (server side, after the form has been posted), include:
if (MyInput.HasFile) ...
var fileName = MyInput.FileName;
var fullPathAndFile = MyInput.PostedFile.FileName;
var mimeType = MyInput.PostedFile.ContentType;
I'm sure all of this stuff can be done, I'm just used to .NET taking care of all of this for me!
Update: after the insightful comments below, I seem to be doing things in an odd manner...
I was originally looking for something along the lines of:
HttpPostedFile file = Request.Files["myFile"];
//accessing the file without having the element itself being runat="server", e.g. manually through the Request.
//(I know this doesn't work without runat="server", just an example to clarify my question)
//if(MyFile.HasFile) ...
if (file != null && file.ContentLength) ...
//var fName = MyFile.FileName
var fName = Path.GetFileName(file.FileName);
But it seems that even that requires runat="server"