Scott Zerby

Scott Zerby

  • NA
  • 1
  • 0

WebClient without filename

Jan 16 2006 2:43 PM
I am an old VB hack, but new to .Net.
 
I am trying to build an application to log on to my online stock web site and download my current position.
 
I now have it using the webbrowser control to successfully log onto the site.  But I am stumped at how to download the file.
 
I do not have a direct web link with the file name, but I do have the direct link to request the file:
 
 

https://wwws.ameritrade.com/cgi-bin/apps/u/BalancesAndPositions?mode=download

 

If I navigate to this page I get a "Save As" dialog box.  How can I download the file silently?

 

I tried this code from an article of your, but I am not sure if it works and where the file (if it is) being downed.

 

Any help would be appreciated!  Thanks!

 

Dim result As String = ""
Try
Dim proxy As New WebProxy(""http://proxy:80/"", True
)
proxy.Credentials =
New
NetworkCredential("userId", "password", "Domain")
Dim request As
WebRequest = WebRequest.Create("https://wwws.ameritrade.com/cgi-bin/apps/u/BalancesAndPositions?mode=download")
request.Proxy = proxy
' Send the 'HttpWebRequest' and wait for response.
Dim response As HttpWebResponse = CType
(request.GetResponse(), HttpWebResponse)
Dim stream As
System.IO.Stream = response.GetResponseStream()
Dim ec As
System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim reader As New
System.IO.StreamReader(stream, ec)
Dim chars() As Char = New
[Char](256)
{}
Dim count As Integer
= reader.Read(chars, 0, 256)
While
count > 0
Dim str = New
[String](chars, 0, 256)
result = result + str
count = reader.Read(chars, 0, 256)
End
While
response.Close()
stream.Close()
reader.Close()
Catch exp As
Exception
Dim str As String
= exp.Message
End
Try