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"
This question seems a little confused.
First off, what do you mean about having another form on a page? ASP.NET pages should have exactly one form (with or without
runat="server").This wording makes me think you have another issue that should be addressed first. It’s extremely unusual to have a valid reason for more than one form on an ASP.NET page.
But if this is what you really need, then remove the ASP.NET tags to your question and replace them with HTML as this would have nothing to do with ASP.NET.