We help IT Professionals succeed at work.
Get Started

ASP FileUpload object is always empty

Last Modified: 2012-05-09
Oops, I accidentally made this a 500 point question and can't seem to change it.  Anyhow, it shouldn't be tough.

I'm simply trying to get the filename select by the user for an upload.  I've spent two hours and can't figure out why it returns an empty string in my code-behind.

A couple of notes:
All of the other controls show their values without issues.  
Intellisense sees "txtFileUpload.FileName"
It is within a form tag.  
It is not in any UpdatePanel.  It IS withing a contentplaceholder in case that has something to do with it.
When I break my code, I switch back to the web page and see the FileUpload value still there.

Lost...  Please help.  Code below
Here's the ASPX code:

                    <td><b>Select File:</b></td>
                      <asp:FileUpload ID="txtFileName" runat="server" Width="350" />                                            
                      <ASP:LinkButton ID="LinkButton1" runat="server" text="Upload Song" />
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtFileName" ErrorMessage="Select a File"></asp:RequiredFieldValidator>

                           OnClientProgressStopped   = "function(){alert('Track uploaded to server!  Thanks.');}"
                           OnClientProgressStarted   = "Clear"
                           OnClientFileRejected      = "Rejected"
                           ShowUploadedFiles         = "true"
                           runat                     = "server"
                           ID                        = "uploadProgress"
                           InnerFiles                = "true"
                           StyleFile                 = "fup_styles/myStyle.css">
                                <fup:Format Ext="mp3"/>
                                <fup:Format Ext="wav"/>
                                <fup:Format Ext="txt"/>
                      <fup:StatusPanel ID="StatusPanel1" runat="server">
                        <asp:Label runat="server" id="uploadedFiles" Text="" />
- C# Code:

            string strSQL = "";
            string cnnString = ConfigurationManager.ConnectionStrings["SmashHausConnectionString"].ConnectionString;
            SqlConnection cn = new SqlConnection(cnnString);

            strSQL = "INSERT INTO metadata (CreationDate, username, Filename, Time, Description, TrackTitle, Category, " + 
                     " SubCategory,BPM,Keywords, " +
                     " FeaturedInstrument, CDTitle, IsVocal) " +
            " VALUES (getdate()," +
                     "'jtsirota','" +                     
                     txtFileName.FileName.ToString().Replace("'", "''") + "','" +
                     txtLength.Text.Replace("'", "''") + "','" +
                     txtDescription.Text.Replace("'", "''") + "','" +
                     txtTrackTitle.Text.Replace("'","''") + "','" +
                     ddCategory.SelectedValue.Replace("'", "''") + "','" +
                     ddSubCategory.SelectedValue.Replace("'", "''") + "','" +
                     txtBPM.Text.Replace("'", "''") + "','" +
                     txtKeywords.Text.Replace("'", "''") + "','" +
                     txtFeaturedInst.Text.Replace("'", "''") + "','" +
                     txtCDTitle.Text.Replace("'", "''") + "','" + 
                     ddIsVocal.SelectedValue + "')";


Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE