开发者

asp.net C# Fileupload always returns false

I am working with a fileuploader to upload a picture. 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. 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.

here is my codebehind.

 if (FileUploadControl.HasFile)
        {
            try
            {
                string filename = Path.GetFileName(FileUploadControl.FileName);
                FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
     开发者_如何学JAVA           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. Make sure the file actually isn't empty.


Your form should have runat="server" instead of method="post" and action="..."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜