FileUpload Control

Last post 09-28-2007 6:21 PM by Tamer Fathy. 7 replies.

Sort Posts:

  • FileUpload Control

    09-26-2007, 1:22 PM
    • Member
      2 point Member
    • asafmgn
    • Member since 08-04-2007, 4:15 PM
    • Israel
    • Posts 11

    hi,

    i am having a problem when using the fileupload control to update my data base with the file that the user selected with the fileupload control.

    after the user selectd the file i want it to bind the link to the database and it seem working ok with the binding but it take alot of time for the page to refresh the page with the new link.it look like it copying somthing or doing somthing that make the HD work and the page load very slowly after i press the "Update" button.

    the only thing i need from the controller is the path for the file and not the file it self.

    my code is:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

    {

     

     

    if(e.CommandName=="Update")

    {

    FileUpload myFileUpload = (FileUpload)GridView1.Rows[GridView1.EditIndex].FindControl("FileUpload1");

    TextBox myTextBox = (TextBox)GridView1.Rows[GridView1.EditIndex].FindControl("Network_File_LinkTextBox");

    string myFileName = myFileUpload.PostedFile.FileName.ToString();if (myFileUpload.PostedFile.FileName != "")

    { myTextBox.Text = myFileName; }

    }

    }

    i have one text box that bind regular text ,and next to it the file upload that pass the user select file to that text box and then the binding is excuted with the new value from the fileupload controll.

     

    i didnt notice the problem with the binding time first because i was chooosing smal file like word file and text file.

    when tried bigger files i got error.so i added this to the config file:

    <httpRuntime executionTimeout="90" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/>

    but when i tried to pick an big avi file (700MB) (i only need the path and name of the file) and press the update button i saw that it take time for the page to refressh with the new details.

     its working but it take allot of time for only i need the path and name.

     

    can some help to understand why it take so mucj time.

    or mabe there is better way to bing the file and path to the sql DB.

     

    thanks in advance.

  • Re: FileUpload Control

    09-26-2007, 3:52 PM
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 8:57 AM
    • Norrköping, Sweden
    • Posts 3,177

    If you don't want the file, but just the path, you shouldn't use the FileUpload control, since that will always try to upload the file. Instead you should use an <input type="file"> (not runat=server!) and move its contents to a hidden field, before submitting the form or when it changes.

     

     

     

    -- "Mark As Answer" if my reply helped you --
  • Re: FileUpload Control

    09-26-2007, 4:26 PM
    • Member
      424 point Member
    • khurramatk2
    • Member since 09-14-2007, 8:43 PM
    • Saudi Arabia
    • Posts 76

    If you put your file upload control outside form tag and on submitting just copy the contents of fileupdate to an form hidden field it can server you purpose . Reason for placing upload control outside form is that it will not be posted to server with the post back hence it will reduce traffice and will be more efficient. it will just work as simple text field submission..

     

    Khurram Shahzad
    K2.Net Workflows
    Dot Net Focus
    Remember to Mark as "Answer" if this helped.
    Filed under: ,
  • Re: FileUpload Control

    09-28-2007, 10:54 AM
    • Member
      2 point Member
    • asafmgn
    • Member since 08-04-2007, 4:15 PM
    • Israel
    • Posts 11

    how can i put the fileupload control outside the Form Tag if it inside my GridView?

     

  • Re: FileUpload Control

    09-28-2007, 11:00 AM
    • Member
      2 point Member
    • asafmgn
    • Member since 08-04-2007, 4:15 PM
    • Israel
    • Posts 11

    i tired using the HTTP Input File Control control without the Runat server propertie i i got the error:

    Object reference not set to an instance of an object.

    Line 48:             HtmlInputFile myFileUpload = (HtmlInputFile)GridView1.Rows[GridView1.EditIndex].FindControl("file1");
    Line 49:             TextBox myTextBox = (TextBox)GridView1.Rows[GridView1.EditIndex].FindControl("Network_File_LinkTextBox");
    Line 50:             string myFileName = myFileUpload.PostedFile.FileName.ToString();
    Line 51:             if (myFileUpload.PostedFile.FileName.ToString() != "")
    Line 52:             {

    my code is:

    HtmlInputFile myFileUpload = (HtmlInputFile)GridView1.Rows[GridView1.EditIndex].FindControl("file1");

    TextBox myTextBox = (TextBox)GridView1.Rows[GridView1.EditIndex].FindControl("Network_File_LinkTextBox");

    string myFileName = myFileUpload.PostedFile.FileName.ToString();if (myFileUpload.PostedFile.FileName.ToString() != "")

    {

    myTextBox.Text = myFileName;

    }

  • Re: FileUpload Control

    09-28-2007, 11:45 AM
    Answer
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 8:57 AM
    • Norrköping, Sweden
    • Posts 3,177

    asafmgn:

    i tired using the HTTP Input File Control control without the Runat server propertie i i got the error:

    Object reference not set to an instance of an object.

    Yes, that's completely logical, since a control without runat=server won't be available on for the server (i.e FindControl)

    This is what I meant:

     <ItemTemplate>
                    <input type="file" onchange="document.getElementById('<%#((GridViewRow)Container).FindControl("hidFile").ClientID%>').value=this.value;" /><asp:HiddenField id="hidFile" runat="server"></asp:HiddenField>
    </ItemTemplate>

    -- "Mark As Answer" if my reply helped you --
  • Re: FileUpload Control

    09-28-2007, 4:08 PM
    • Member
      2 point Member
    • asafmgn
    • Member since 08-04-2007, 4:15 PM
    • Israel
    • Posts 11

    thanks that did the trick.Big SmileYes

  • Re: FileUpload Control

    09-28-2007, 6:21 PM
    • Participant
      1,174 point Participant
    • Tamer Fathy
    • Member since 09-28-2007, 3:28 PM
    • Posts 225

     hi,

    Try this sample it was good one i try it me self

    http://www.codeproject.com/aspnet/FileHandlerPackage.asp

    http://www.codeproject.com/useritems/ASPNET20FileUpload.asp 

    Tamer Fathy
    MCAD .NET
    http://tamer-fathy.blogspot.com/

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
Page 1 of 1 (8 items)