Results 1 to 18 of 18

Thread: [2008] Download text from internet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    Exclamation [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.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Download text from internet

    To download the text from a document on the internet, use the WebClients DownloadString method.
    VB.NET Code:
    1. Dim text As String
    2.         Using client As New System.Net.WebClient
    3.             text = client.DownloadString("http://....")
    4.         End Using
    Then you'd have to parse out the part(s) you need from the downloaded string.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    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?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    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.

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    Re: [2008] Download text from internet

    and can I do all that in my app?

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Download text from internet

    Quote 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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    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

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim byteData() As Byte
    2.         Using client As New Net.WebClient
    3.             client.Credentials = New System.Net.NetworkCredential("user", "password")
    4.             byteData = client.DownloadData("ftp://....")
    5.             ' Do whatever you want to the byteData array; write it to a file or modify it directly.
    6.         End Using

    Uploading is done in a similar fashion.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    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?

  11. #11
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Download text from internet

    Quote 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

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    Re: [2008] Download text from internet

    lol, webclient.uploadfile seemed like a good idea, till the dreaded blue zigzag appears...

  14. #14
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Download text from internet

    Quote 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:
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         Dim wc As New Net.WebClient
    4.         wc.UploadFile("ftp://somewhere.com", "somefile.txt")
    5.     End Sub
    6. End Class
    http://msdn2.microsoft.com/en-us/library/36s52zhs.aspx

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Download text from internet

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    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?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2007
    Posts
    73

    Re: [2008] Download text from internet

    any help would be great

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width