Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to process a file upload in ASP.NET with a form that does NOT have runat="server"?
    primarykey
    data
    text
    <p>For reasons beyond this question, I cannot have a form on this page with a <code>runat="server"</code> attribute.</p> <p>How do I go about accessing an uploaded file uploaded using a regular <code>&lt;input type="file"...</code>?</p> <p><a href="https://stackoverflow.com/questions/569565/uploading-files-in-asp-net-without-using-the-fileupload-server-control">This question</a> touches on the issue, (using an <code>&lt;input type="file"</code> rather than an <code>&lt;asp:FileUpload</code>), however they still both runat=server.</p> <p>The types of things I would like to be able to acheive (server side, after the form has been posted), include:</p> <ul> <li><code>if (MyInput.HasFile) ...</code></li> <li><code>var fileName = MyInput.FileName;</code></li> <li><code>var fullPathAndFile = MyInput.PostedFile.FileName;</code></li> <li><code>var mimeType = MyInput.PostedFile.ContentType;</code></li> </ul> <p>I'm sure all of this stuff can be done, I'm just used to .NET taking care of all of this for me!</p> <p><strong>Update:</strong> after the insightful comments below, I seem to be doing things in an odd manner...</p> <p>I was originally looking for something along the lines of:</p> <pre><code>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 &amp;&amp; file.ContentLength) ... //var fName = MyFile.FileName var fName = Path.GetFileName(file.FileName); </code></pre> <p>But it seems that even that requires <code>runat="server"</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload