Library tutorials & articles
Interacting with the web using WebRobot v1.0
By Fernando Sanchez, published on 17 May 2006
Page 5 of 5
- Logging in to MySpace
- Uploading files to YouSendIt
- Uploading files to YouSendIt: Adding fields
- Uploading files to YouSendIt: Setting form values
- Uploading files to YouSendIt: Submitting the form
Uploading files to YouSendIt: Submitting the form
Now, we are ready to submit our form:
You can obtain the WebRobot component at http://foxtrot-xray.com/web-robot
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim wrobot As New foxtrot.xray.WebRobot
wrobot.Base = "http://www.yousendit.com/"
wrobot.LoadPage("/")
'getting file upload form from page
Dim wform As foxtrot.xray.Form = wrobot.GetFormByName("tform")
wform.AddField("text", "rcpt")
wform.AddField("file", "fname")
wform.AddField("hidden", "rurl", _
"http://www.yousendit.com/transfer.php?action=status")
'creating an Open File Dialog to choose file to upload
Dim fopendialog As New System.Windows.Forms.OpenFileDialog
fopendialog.CheckFileExists = True
If fopendialog.ShowDialog() = DialogResult.OK Then
'open file for reading
Dim fstream As New System.IO.FileStream(fopendialog.FileName, _
IO.FileMode.Open)
'temporary buffer to store contents of file
Dim bytFile(fstream.Length - 1) As Byte
'read in the file
fstream.Read(bytFile, 0, fstream.Length)
'the contents of the file to be uploaded to the server
Dim mstream As New System.IO.MemoryStream(bytFile)
'getting email field by name from form
Dim wemail As foxtrot.xray.Input = wform.GetFieldByName("rcpt")
'getting file upload field from form
Dim wfile As foxtrot.xray.Input = wform.GetFieldByName("fname")
'set your recipient's email here
wemail.InputValue = "none@domain.com"
'assign contents of file to the form field
wfile.InputValue = mstream
'assign filename to be sent
wfile.InputFileName = fopendialog.FileName
Dim progressid As String
'regular expression to find the PROGRESS_ID
'variable in the HTML source
Dim regex As New System.Text.RegularExpressions.Regex_
("var\sPROGRESS_ID\s=\s""(?<progid>\d+)"";")
If (regex.IsMatch(wrobot.HTMLSource) = True) Then
progressid = regex.Match(wrobot.HTMLSource).Result("${progid}")
'modifying the form action
wform.FormAction = wform.FormAction & "/" & progressid
wrobot.SubmitForm(wform) 'submit form
MessageBox.Show("File uploaded successfully")
Else
MessageBox.Show("YouSendIt PROGRESS_ID variable not found, _
cannot continue with upload!")
End If
End If
End Sub
If you want to fill out forms, or upload files, the WebRobot component is the way to go. It simplifies your life by taking care of all the underlying details of your web requests for you. You can obtain the WebRobot component at http://foxtrot-xray.com/web-robot
Related articles
Related discussion
-
Sharepoint : GroupBy results according to custom property
by sampadasanjay (0 replies)
-
i have struck with my project in vb.net
by jetski (4 replies)
-
Error in VB code
by glib162002 (0 replies)
-
Very slow inserts using SqlCommand.ExecuteNonQuery()
by porchelvi (1 replies)
-
Datagridview Setting datasource property of datagridviewcomboboxcell at run time
by sairfan1 (2 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum)
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
Yes it'll save a plenty of work, thanks .
That looks very nice. It'll save me plenty of work when posting a form instead of hardcoding all the fields in a webrequest! http://www.fixx.be
This is a Very Good Example.I thin its very usefull to me.
but the problem is when i try this this not work properly error occured at this line "Dim wrobot As New foxtrot.xray.WebRobot()"
it displayes "File or Assembly name System,or one of its dependancies was not found."
Please answer to me.
This thread is for discussions of Interacting with the web using WebRobot v1.0.