Asp.Net中的文件上传选项 [英] File Upload Option in Asp.Net

查看:62
本文介绍了Asp.Net中的文件上传选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我在表单中添加了文件上传选项.但是当我检查Fileupload.HasFile时,即使我选择了文件,它也会给出false.
代码如下:

Dear Friends,

I have added a file upload option in my form. But when I check Fileupload.HasFile it give false even when I select the file.
Code Below:

<asp:FileUpload

                                        ID="Resume_File"

                                        runat="server"

                                        BackColor="DodgerBlue"

                                        ForeColor="AliceBlue" />
                                        <asp:Button runat="server" id="Up_Resume_File" text="Upload"

                                            onclick="Up_Resume_File_Click"/><br /><br />
                                        <asp:Label runat="server" id="StatusLabel" text="Upload status: " />


protected void Up_Resume_File_Click(object sender, EventArgs e)
    {
        if (Resume_File.HasFile)
        {
            StatusLabel.Text = "Yes";
        }
        else
        {
            StatusLabel.Text = "No";
        }
    }



请对此进行指导,我哪里出错了.



Kindly guide me on this, where I am gone wrong.

推荐答案

[ http://stackoverflow.com/questions/5848523/fileupload1-hasfile-is-always- returning-false [ ^这也]
[Check this link.. it may help you..]

http://stackoverflow.com/questions/5848523/fileupload1-hasfile-is-always-returning-false[^This also]


尝试一下:
Try This out:
protected void Up_Resume_File_Click(object sender, EventArgs e)
{
    if (Resume_File.PostedFile.FileName!= string.Empty)
    {
        StatusLabel.Text = Yes;
    }
    else
    {
        StatusLabel.Text = No;
    }
}


您的代码仅是正确的.如我所料,您已在更新面板中进行了文件上传控制(您可以在
Your code is correct only. As I guessed, you have taken your file upload control inside the update panel(You can see the same situation here[^]). Remove the update panel and check it again.

Alternative solution:
Add a trigger for UpdatePanel:
<triggers>
   <asp:postbacktrigger controlid="btnCertificateUpload" />
</triggers>


单击上传按钮时,这将强制回发.

之后,将以下行添加到Page_Load:


This will force a postback when the upload button is clicked.

After that add the below line to the Page_Load:

Page.Form.Attributes.Add("enctype", "multipart/form-data");




希望对您有所帮助.!
--Amit




Hope it helps.!
--Amit


这篇关于Asp.Net中的文件上传选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆