Uploading files in asp.net 2.0?

  • Thread starter Thread starter midasforever
  • Start date Start date
M

midasforever

Guest
I need help. I am using visual studio 2005 professional on Vista and I am building a website in ASP.net 2.0 and using VB for my code behind pages. I have been looking for four days to figure out a way to upload the pictures to a folder on the website and save the file path in a database.

I have used 4 different sets of code, and only one worked and only then it worked halfway. Here is my current code:

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.ServerClick

If Not (UploadFilePath.PostedFile Is Nothing) Then
Try
Dim strFilePath As String
strFilePath = System.IO.Path.
GetDirectoryName(Server.MapPath("UploadContent.aspx"))
UploadFilePath.PostedFile.SaveAs
((strFilePath & "\ImageUploads" & txtFileName.Value))
textlbl.Text = _
"You file was uploaded successfuly" & _
"<br />to the web server at<br />" & "<b>" & strFilePath & _

"\ImageUploads" & txtFileName.Value & "</b>"
HyperLink1.NavigateUrl = "\ImageUploads" _
& txtFileName.Value
HyperLink1.Visible = True

Catch exc As Exception
textlbl.Text = "Error saving file. <br>" _
& exc.Message
End Try
End If
End Sub

That is the code on my code behind page. When you test it, it says it is uploading the file but,when you browse to the folder there are no pictures in it. This is where I need help. Why is it acting like it is working when it is not? Please forgive the formatting. I had to break it up some because of yahoo.
 
Back
Top