文件上传不工作 [英] File Upload is not working

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

问题描述

我用我的网站文件上传。我上传的Word文档(DOC,DOCX)。突然,它不工作。它是没有得到的文件名。这正显示出空!我的code是如下:

I'm using file upload in my site. I'm uploading word Document(Doc,Docx). Suddenly, it's not working. It is not getting the filename. It is showing empty!!! My Code is as follows:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">

<table width="100%" align="center">
    <tr>
        <td style="height: 21px" align="center">
            <span class="lbl"></span>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnResumedload" Text="Download Resume" runat="server" BackColor="Maroon"
                        ForeColor="White" Font-Bold="true" OnClick="btnResumedload_Click" Height="27px"
                        Width="195px" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnUploadnew" Text="Upload New" runat="server" BackColor="Maroon"
                        ForeColor="White" Font-Bold="true" OnClick="btnUploadnew_Click" Height="30px"
                        Width="198px" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnDel" Height="30px" Width="198px" OnClientClick="return confirm('Are you sure?');"
                        BackColor="Maroon" ForeColor="White" Font-Bold="true" Text="Delete Resume" runat="server"
                        OnClick="btnDel_Click"></asp:Button>
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"
                Height="17px" Width="855px"></asp:Label>
        </td>
    </tr>
    <tr>
        <td align="center">
            <span class="txt">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <%--<ajaxToolkit:AsyncFileUpload ID="fpResumenew" runat="server" Visible="false" />--%>
                        <asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnUpload" />
                    </Triggers>
                </asp:UpdatePanel>
            </span>
        </td>
    </tr>
    <tr>
        <td align="center">
            &nbsp;
        </td>
    </tr>
    <tr>
        <td style="vertical-align: top" align="center">
            <%--<asp:Button ID="btnUpload" Font-Bold="true" DisabledText="Processing..." Visible="false"
                        Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />--%>
            <cc1:ClickOnceButton ID="btnUpload" Font-Bold="true" DisabledText="Processing..."
                Visible="false" Text="Upload" BackColor="Maroon" ForeColor="White" runat="server"
                OnClick="btnUpload_Click" DisableAfterClick="True" />
        </td>
    </tr>
</table>

保护无效btn_Click(对象发件人,EventArgs五)

protected void btn_Click(object sender, EventArgs e)

{

    string strfilename = fp.FileName.ToString();

    if (fp.PostedFile.FileName.Trim().Length != 0)

    {

        binary = new byte[fp.PostedFile.ContentLength];

        binary = fp.FileBytes;

        doc = fp.FileName;

        contenttype = fp.PostedFile.ContentType;


    }

}

只是一个样本!

没有什么工作对我来说..问题是,我使用在同一页面三个按钮。其他按钮初始化文件上传控件。因此,点击上传按钮时,文件名是空的。所以,我用另一个页面上传Word文档。现在,它是工作.. !!无论如何,我需要为这个解决方案!任何人给我的想法!

Nothing works for me.. Problem is that I'm using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !! Anyhow, I need the solution for this!! Anyone give me idea!!

推荐答案

的FileUpload控件不兼容的UpdatePanel

FileUpload controls are not compatible with UpdatePanel when they are used to upload files as part of an asynchronous postback.

只是检查了AJAX文档。 FileUpload控件不是一个UpdatePanel( http://ajax.asp.net/docs内支持/overview/UpdatePanelOverview.aspx ):

Just check the AJAX documentation. The FileUpload control is not supported inside an UpdatePanel (http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx):

使用ASP:postbacktrigger代替asyncpostbacktrigger

use asp:postbacktrigger instead of asyncpostbacktrigger

<asp:updatepanel runat="server" id="UpdatePanel1">
    <contenttemplate>
        <asp:FileUpload runat="server" id="FileUpload1" />
        <asp:button runat="server" id="ButtonSubmit" text="Postback" />
    </contenttemplate>
    <triggers>
        <asp:postbacktrigger controlid="ButtonSubmit" />
    </triggers>

</asp:updatepanel>

使用AJAX异步文件上传:

use ajax for asynchronous file upload:

<一个href=\"http://www.asp.net/%28S%28fu2l2uzphr2u3u45q2dnez55%29%29/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx\" rel=\"nofollow\">http://www.asp.net/(S(fu2l2uzphr2u3u45q2dnez55))/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx

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

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