We help IT Professionals succeed at work.

I need help with a FileUpload Control in ASP.Net 3.5

mainrotor
mainrotor asked
on
573 Views
Last Modified: 2012-05-11
HiExperts,
I am using a FileUpload control in my Asp.net 3.5 application with VB.Net codebehind.  I want to set a string variable equal to the FilePath of the file in my FileUploadControl, how do i do that?

Thanks in advance,
mrotor
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
CodeCruiser, I tried that and I get an error.  What could be the problem?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
How do I know without knowing what the error is?
Can you please post the error for us to understand in better way?

Author

Commented:
Okay below is my code where I want to retrieve the name of the File in the FileUpload control and try to display it in a Label.  If I browse for a file and click my Test button, then the Label accurately displays the message "You have not specified a file."  The minute I do browse for a file I get the generic error Internet Explorer error message.  I have included a Print Screen of the error message.  What is wrong?

    Protected Sub Test_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Test.Click
       
      If (FileUpload1.HasFile = True) Then
            Try
                lblTest.Text = "File name: " & FileUpload1.PostedFile.FileName
            Catch ex As Exception
                lblTest.Text = "ERROR: " & ex.Message.ToString()
            End Try
        Else
            lblTest.Text = "You have not specified a file."
        End If
    End Sub

Thanks in advance,
mrotor

Error.bmp
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
havj123
I stopped getting an error after I added the following code to the web.config:

    <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
    </customErrors>

mrotor
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.