FileUpload控件难道不ASP.NET中工作 [英] fileupload control wouldnt work in ASP.NET
本文介绍了FileUpload控件难道不ASP.NET中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
林试图与ASP.NET简单uploadfile控制,
它难道不工作:
Im trying to make a simple uploadfile control with ASP.NET, and it wouldnt work:
<form id="form1" runat="server">
<div>
upload a file now.
<asp:FileUpload ID="fileupload1" runat="server" />
<asp:Button ID="button1" Text="Upload" runat="server" Width="73px"
onclick="button1_Click" />
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#000099">
</asp:Label>
</div>
</form>
和后面(的.cs)我的继承人code:
if(fileupload1.HasFile)
{
try
{
if(fileupload1.PostedFile.ContentType == "image/jpeg")
{
if(fileupload1.PostedFile.ContentLength < 51200000)
{
string filename = Path.GetFileName(fileupload1.FileName);
fileupload1.SaveAs(Server.MapPath("~/img/") + filename);
Label1.Text ="File uploaded successfully!";
}
else
Label1.Text ="File maximum size is 500 Kb";
}
else
Label1.Text ="Only JPEG files are accepted!";
}
catch(Exception exc)
{
Label1.Text = "The file could not be uploaded. The following error occured: "
+ exc.Message;
}
}
的
文件不在服务器psented $ P $ ..
什么想法?
the file is not presented in the server.. any thoughts?
当我断点,他们一切都有效,应用程序获取到code,这一切工作,但不会将其保存到文件夹..
when I breakpoint, they all goes valid, the application gets to the code, it all working , but wont save it to the folders..
推荐答案
这可能会或可能不会完全工作,但您需要在您的形式的是enctype
属性。
This may or may not work entirely, but you need to include an enctype
attribute in your form.
<form id="form1" runat="server" enctype="multipart/form-data">
如果你不这样做,浏览器将无法传输文件。
If you don't do that, browsers won't transfer the file.
在这里看到:的https://developer.mozilla .ORG / EN-US /文档/ HTML /元/形式#ATTR-ENCTYPE
这篇关于FileUpload控件难道不ASP.NET中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文