digitaldrew
Well-known member
- Joined
- Nov 10, 2012
- Messages
- 167
- Programming Experience
- Beginner
Hey everyone..I'm working to submit a mutlipart form using HTTPWebRequest and everything appears to be working - except for one part.
The program should be submitting 3 fields - a name, a source, and an image. I'm using openfiledialog to let the user select the image they want to submit and then setting that location into a textbox. Since the form I'm submitting to only uses the filename (not the entire location) I am splitting the file location path and only passing the actual filename (that ends with .jpg, .png, or .gif)
Here is the issue..When trying to submit the form I get an exception everytime. The exception is saying "Could not find file 'C:\Users\Drew\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\Image.jpg'."
I can't figure out why it's looking into this visual studio debug folder when the file locaton specified in the textbox is C:\Users\Drew\Desktop\Image.jpg
Here is part of my code
What could I be doing wrong here? as you see I have MsgBox(line) directly under my split and that messagebox shows the appropriate filename that should be getting passed (Image.jpg)..but yet it still catches the exception everything??
The program should be submitting 3 fields - a name, a source, and an image. I'm using openfiledialog to let the user select the image they want to submit and then setting that location into a textbox. Since the form I'm submitting to only uses the filename (not the entire location) I am splitting the file location path and only passing the actual filename (that ends with .jpg, .png, or .gif)
Here is the issue..When trying to submit the form I get an exception everytime. The exception is saying "Could not find file 'C:\Users\Drew\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\Image.jpg'."
I can't figure out why it's looking into this visual studio debug folder when the file locaton specified in the textbox is C:\Users\Drew\Desktop\Image.jpg
Here is part of my code
VB.NET:
Try
Dim strResponse As String
Dim cHTTP As New http
' Set up POST data
Dim pdlPostData As New http.PostDataList ' Form fields
pdlPostData.Add("title", txtPostTitle.Text)
pdlPostData.Add("source", txtSourceUrl.Text)
pdlPostData.Add("submit", "Submit")
Dim mpfPictureFile As New http.MultipartPostFile ' File to upload
mpfPictureFile.Name = "foto"
Dim lines() As String = txtImage.Text.Split("\")
For Each line In lines
If line.Contains(".jpg") Or line.Contains(".gif") Or line.Contains(".png") Then
MsgBox(line)
mpfPictureFile.Path = line
End If
Next
mpfPictureFile.ContentType = "application/octet-stream"
' Send request now
strResponse = cHTTP.PostMultipartRequest(selectedSite, pdlPostData, mpfPictureFile, selectedSite, , , "text/html", , , True)
' Determine success
If InStr(strResponse, "Image sent!") > 0 Then
' Picture submitted
informationB = "Picture successfully submitted!"
Else
' Failed to submit picture
informationB = "Failed to submit picture!"
End If
Catch ex As Exception
MsgBox(ex.Message)
If lstWlol.InvokeRequired Then
lstWlol.Invoke(Sub() lstWlol.SetItemChecked(r, False))
lblUnsuccessful.Invoke(Sub() lblUnsuccessful.Text = lblUnsuccessful.Text + 1)
txtLog.Invoke(Sub() txtLog.AppendText("Website Gave an Error and Has Been Unchecked" & vbCrLf))
End If
Continue For
End Try
What could I be doing wrong here? as you see I have MsgBox(line) directly under my split and that messagebox shows the appropriate filename that should be getting passed (Image.jpg)..but yet it still catches the exception everything??