[英]asp.net C# Fileupload always returns false
I am working with a fileuploader to upload a picture. 我正在使用fileuploader上传图片。 However, evertyime i select the file and click the upload button it says that the fileuploader.file returns a value of false and does not run the next lines of code.
但是,evertyime我选择了文件,然后单击上载按钮,它说fileuploader.file返回的值为false,并且不运行下一行代码。 All i can find is that it has to be in in a seperate form and that the method has to be "post", but that did not fix the problem.
我所能找到的就是它必须采用单独的形式,并且该方法必须是“ post”的,但这并不能解决问题。
here is my codebehind. 这是我的代码背后。
if (FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
here is my front end code. 这是我的前端代码。
<form id="form2" action="CompProfile.aspx" method="post" enctype="multipart/form-data">
<asp:FileUpload id="FileUploadControl" runat="server" />
<asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
<asp:Label runat="server" id="StatusLabel" text="Upload status: " />
</form>
If you are testing with a 0 byte sized file it will return false. 如果使用0字节大小的文件进行测试,它将返回false。 Make sure the file actually isn't empty.
确保文件实际上不是空的。
您的表单应具有runat="server"
而不是method="post"
和action="..."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.