|
-
Apr 13th, 2008, 06:27 AM
#1
Thread Starter
Lively Member
[2008] Download text from internet
Hey, I'm trying to get a line of text from a webpage, and put it in a label. Just some experimenting stuff. I have this to download an image:
Code:
PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(TextBox1.Text)))
Just wondering if theres anything I can do from that for this 
Thanks in advance
Last edited by want a pie; Apr 13th, 2008 at 06:35 AM.
-
Apr 13th, 2008, 06:38 AM
#2
Re: [2008] Download text from internet
To download the text from a document on the internet, use the WebClients DownloadString method.
VB.NET Code:
Dim text As String
Using client As New System.Net.WebClient
text = client.DownloadString("http://....")
End Using
Then you'd have to parse out the part(s) you need from the downloaded string.
-
Apr 13th, 2008, 06:45 AM
#3
Thread Starter
Lively Member
Re: [2008] Download text from internet
Thanks, but it just gives me the script of the website, is there any way that I can get the text from the site?
-
Apr 13th, 2008, 06:52 AM
#4
Thread Starter
Lively Member
Re: [2008] Download text from internet
nevermind, realised that it can read from text files, which is great will rate you
while I'm here, is there any way that I can type into the .txt file that's in my ftp? (keep in mind I'm pretty nooby at VB and internet stuff)
Last edited by want a pie; Apr 13th, 2008 at 06:56 AM.
-
Apr 13th, 2008, 06:59 AM
#5
Re: [2008] Download text from internet
You can not directly modify a file on an FTP server. As the name File Transfer Protocol implies, you can only transfer files from and to the server. You will have to download the text file, modify it, and send it back to the server.
-
Apr 13th, 2008, 07:06 AM
#6
Thread Starter
Lively Member
Re: [2008] Download text from internet
and can I do all that in my app?
-
Apr 13th, 2008, 07:06 AM
#7
Re: [2008] Download text from internet
 Originally Posted by want a pie
and can I do all that in my app?
Sure, take a look at the System.Net.FtpWebRequest class.
-
Apr 13th, 2008, 07:20 AM
#8
Thread Starter
Lively Member
Re: [2008] Download text from internet
looked at it, and have no idea what to do... sort of got a little bit into the create, but I hav no idea how to put in a password, has it got something to do with
Code:
New System.Net.NetworkCredential
-
Apr 13th, 2008, 07:30 AM
#9
Re: [2008] Download text from internet
Ah I seem to have confused myself there for a moment. You can use the WebClient to download/upload files from/to FTP servers
VB.NET Code:
Dim byteData() As Byte
Using client As New Net.WebClient
client.Credentials = New System.Net.NetworkCredential("user", "password")
byteData = client.DownloadData("ftp://....")
' Do whatever you want to the byteData array; write it to a file or modify it directly.
End Using
Uploading is done in a similar fashion.
-
Apr 13th, 2008, 08:44 AM
#10
Thread Starter
Lively Member
Re: [2008] Download text from internet
ok, I have no idea how I'm supposed to do the uploading, so could u get me started?
-
Apr 13th, 2008, 08:51 AM
#11
Re: [2008] Download text from internet
 Originally Posted by want a pie
ok, I have no idea how I'm supposed to do the uploading, so could u get me started?
MSDN again to the rescue. http://msdn2.microsoft.com/en-us/library/tdbbwh0a.aspx
-
Apr 13th, 2008, 08:53 AM
#12
Re: [2008] Download text from internet
If you're using the WebClient.DownloadFile or DownloadData method to download files or data, what do you suppose you might use to upload files or data?
-
Apr 13th, 2008, 08:59 AM
#13
Thread Starter
Lively Member
Re: [2008] Download text from internet
lol, webclient.uploadfile seemed like a good idea, till the dreaded blue zigzag appears...
-
Apr 13th, 2008, 09:07 AM
#14
Re: [2008] Download text from internet
 Originally Posted by want a pie
lol, webclient.uploadfile seemed like a good idea, till the dreaded blue zigzag appears...
Care to share your code?
No errors here:
vb.net Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wc As New Net.WebClient
wc.UploadFile("ftp://somewhere.com", "somefile.txt")
End Sub
End Class
http://msdn2.microsoft.com/en-us/library/36s52zhs.aspx
-
Apr 13th, 2008, 09:14 AM
#15
Re: [2008] Download text from internet
 Originally Posted by want a pie
lol, webclient.uploadfile seemed like a good idea, till the dreaded blue zigzag appears...
As nmadd suggests, it serves neither us nor you to tell us that you get errors if you don't show us what you're doing and tell us what error messages you get. Ringing the mechanic and telling him that your car won't go doesn't get it fixed.
-
Apr 13th, 2008, 09:44 PM
#16
Thread Starter
Lively Member
Re: [2008] Download text from internet
using nmadd's code I got this error:
An exception occurred during a WebClient request.
Could it have something to do with the ftp I'm trying to access?
-
Apr 14th, 2008, 10:02 PM
#17
Thread Starter
Lively Member
Re: [2008] Download text from internet
any help would be great
-
Apr 14th, 2008, 10:15 PM
#18
Re: [2008] Download text from internet
We already know that an error occurred during the WebClient request. You've still told us nothing. You need to provide us with all the information that the IDE has provided you with. That's why the IDE provides the information: to help diagnose the issue. You have to show us the exact code that you're executing and you have to show us all the details of the exception. Have you actually clicked the View Details link on the Unhandled Exception dialogue? Have you considered actually catching the exception and interrogating it yourself?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|