0

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
            {

            }
        }
    }
Victor
  • 555
  • 6
  • 15
  • 39
  • I guess the source of the problem is not the "tabbed interface". Would you please provide your code/markup .. – Akram Shahda Jun 28 '11 at 10:05
  • Hi thank you for giving response i have post my code in question tag please find the code and help me please... – Victor Jun 28 '11 at 10:12
  • @Victor `btnfupload_Click` code pls... – Nika G. Jun 28 '11 at 10:20
  • while i upload file in normal page(without Tabbed interface)it is uploded correctly... – Victor Jun 28 '11 at 10:27
  • i using this http://www.codeproject.com/KB/ajax/AJAXTabControl.aspx for tabbed interface in my project – Victor Jun 28 '11 at 10:37
  • u said `when i try to upload a file it doesn't take the file it always show the null value`. What shows `NULL`? u mean `FileUpload1.HasFile` is always `false` and it never passes the `if` condition? **EDITED** also - FileUpload1 already has file name with extension. `FileUpload1.FileName` gives filename, no need to do the `string docment = FileUpload1.PostedFile.FileName; string path=System.IO.Path.GetFileName(docment);` – Nika G. Jun 28 '11 at 10:46
  • yes it always false it goes to else part. – Victor Jun 28 '11 at 10:48
  • ok thank you i can change that in my code,but need to FileUpload1.HasFile condition True ,,How? – Victor Jun 28 '11 at 10:59
  • Ajax and asp FileUpload... now ic whats causing problem. follow [The link](http://stackoverflow.com/questions/5848523/fileupload1-hasfile-is-always-returning-false) or use the AsyncFileUpload as already suggested... or u can try to google... – Nika G. Jun 28 '11 at 11:23

1 Answers1

1

Use AsyncFileUpload:

Akram Shahda
  • 14,655
  • 4
  • 45
  • 65
Saurabh
  • 5,661
  • 2
  • 26
  • 32