简体   繁体   中英

How to upload a file in asp.net in Tabbed interface control

I have a asp.net(c#) web application in that i am using Tabbed interface to show the forms.In Tabbed interface there are 4 tabs are there in 4th tab i have file upload control,when i try to upload a file it doesn't take the file it always show the null value.How can i upload the file in Tabbed interface please help me.

<cc1:TabPanel runat="server" HeaderText="Documents" ID="TabPanel4">
    <triggers>
        <asp:PostBackTrigger ControlID="SyncButton" />
    </triggers>
    <ContentTemplate>
        <asp:Button ID="SyncButton" runat="server" Text="Test" />
        <table>
            <tr>
                <td>Documnets</td>
            </tr>
            <tr>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                    <br />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnfupload" runat="server" 
                        CausesValidation="false" Text="Upload File"
                        OnClick="btnfupload_Click" />
                </td>
                <td>
                    <asp:Label ID="lblstatus" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</cc1:TabPanel>

Code Behind:

           protected void btnfupload_Click(object sender, EventArgs e)
    {

            try
            {
                if (FileUpload1.HasFile)
                {
                    if (!Directory.Exists(Server.MapPath("Documents")))
                    {
                        Directory.CreateDirectory(MapPath("Documents"));

                    }
                    string docment = FileUpload1.PostedFile.FileName;
                    string path = System.IO.Path.GetFileName(docment);
                    FileUpload1.PostedFile.SaveAs(Server.MapPath("Documents/") + path);

                }
            }
            catch
            {

            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM