由於無法解決此問題的原因,我無法在此頁面上使用runat="server"
屬性。如何使用沒有runat =「server」的表單處理ASP.NET中的文件上傳?
如何訪問使用常規<input type="file"...
上傳的上傳文件?
This question涉及該問題(使用<input type="file"
而不是<asp:FileUpload
),但它們仍然runat = server。
類型的事情,我希望能夠acheive(服務器端,形式已經發布之後),包括:
if (MyInput.HasFile) ...
var fileName = MyInput.FileName;
var fullPathAndFile = MyInput.PostedFile.FileName;
var mimeType = MyInput.PostedFile.ContentType;
我確定所有這些東西都可以做ne,我只是習慣.NET爲我處理所有這些事情!
更新:下面有見地的意見後,我好像在一個奇怪的方式來做事...
我本來想找沿着線的東西:
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);
但它似乎甚至需要runat="server"
我在下面提供了一個答案,但爲什麼你想這樣做超出了我。即使你使用的是Html控件,你可以爲它提供服務器端邏輯的唯一方法就是通過添加runat =「server」... – IrishChieftain 2011-04-29 00:59:22