-
Jul 27th, 2020, 11:49 PM
#1
Thread Starter
New Member
How to copy text from some internet document to RichTextBox?
I want my RichTextBox1 in Form1 to show the text from some document, placed, for example, on my website or in DropBox or somewhere else. I mean only the text, not the whole document.
If I update the text in the same document, these changes will be visible at all users of my exe windows application.
Is this possible?
I tried something like this using DropBox, but instead of text I get some html code in my RichTextBox:
Code:
Dim myWebClient As New System.Net.WebClient
Dim file As New System.IO.StreamReader(myWebClient.OpenRead("https://www.dropbox.com/scl/fi/op7twrbru0ggf77auh709/My-Paper-doc.paper?dl=0&rlkey=085ge69iq0d3kwhe5bilk34t6"))
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
RichTextBox1.Clear()
RichTextBox1.Text = file.ReadToEnd()
file.Close()
End Sub
-
Jul 27th, 2020, 11:57 PM
#2
Re: How to copy text from some internet document to RichTextBox?
I don't use DropBox but I would assume that the URL you are using there is not for the file itself but, rather, for a web page that displays the contents of the file. If you open that URL in a browser and examine the source, what do you see? That's what you're going to get from that code. If you want just the file contents then you're going to have to look at what DropBox provides to access just the file contents. Maybe it offers an alternative API or FTP access or the like. If not then you're going to have to write code to scrape the file contents from that web page.
-
Jul 28th, 2020, 02:43 AM
#3
Re: How to copy text from some internet document to RichTextBox?
Originally Posted by ZlayaNewbie
I want my RichTextBox1 in Form1 to show the text from some document, placed, for example, on my website or in DropBox or somewhere else. I mean only the text, not the whole document.
If I update the text in the same document, these changes will be visible at all users of my exe windows application.
Is this possible?
I tried something like this using DropBox, but instead of text I get some html code in my RichTextBox:
Code:
Dim myWebClient As New System.Net.WebClient
Dim file As New System.IO.StreamReader(myWebClient.OpenRead("https://www.dropbox.com/scl/fi/op7twrbru0ggf77auh709/My-Paper-doc.paper?dl=0&rlkey=085ge69iq0d3kwhe5bilk34t6"))
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
RichTextBox1.Clear()
RichTextBox1.Text = file.ReadToEnd()
file.Close()
End Sub
Hello ZlayaNewbie,
Unless your documents are plain-text you will need to use a method specific to the format in question to load and display a particular document. Also, a coding tip:
If you you use imports either at the project or code-file level you can write your code as follows:
Code:
Imports System
Imports System.IO
Imports System.Net
Dim myWebClient As New WebClient
Dim file As New StreamReader(myWebClient.OpenRead("https://www.dropbox.com/scl/fi/op7twrbru0ggf77auh709/My-Paper-doc.paper?dl=0&rlkey=085ge69iq0d3kwhe5bilk34t6"))
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RichTextBox1.Clear()
RichTextBox1.Text = file.ReadToEnd()
file.Close()
End Sub
See? It makes the lines shorter and easier to read. Also less typing.
Yours,
Peter Swinkels
-
Jul 28th, 2020, 06:53 AM
#4
Thread Starter
New Member
Re: How to copy text from some internet document to RichTextBox?
jmcilhinney & Peter Swinkels
Thank you both for your fast response.
It is the same outcome with your code, Peter.
Regarding the DropBox, it seems to me should not be feasible. Maybe there is another way.
For further explanation, I have made a simple subpage with only one textbox on the link below:
https://winding.wixsite.com/stan-u-doboju/blank
-
Jul 28th, 2020, 08:09 AM
#5
Re: How to copy text from some internet document to RichTextBox?
@zlayanewbie: the code I posted was just an example on how you could improve your code's style. Not what it does. Also, I told you you need to use format specific methods to retrieve the desired contents from a file. If you could provide more information about what file types you want fo copy into your RichTextBox you stand a better chance of getting a reply helping you with your specific question.
-
Jul 28th, 2020, 10:31 AM
#6
Thread Starter
New Member
Re: How to copy text from some internet document to RichTextBox?
Hi, Peter,
How to find out the file type I want to copy into RichTextBox?
-
Jul 28th, 2020, 10:40 AM
#7
Re: How to copy text from some internet document to RichTextBox?
Hi ZlayaNewbie,
You would normally do that by looking at the file's extension. If you haven't already done so, you might want to enable displaying extensions in Explorer:
How do I show file extensions?
Fortunately, it only takes a few steps:
Choose My Computer from the Windows Start menu. (You can use any method for launching Explorer.)
Choose Folder Options from the Tools menu and click the View tab.
In the Folder Options dialog box, uncheck the Hide Extensions For Known File Types option.
Click OK.
You will also need to examine the file's contents. Often the header will contain a signature of a few bytes. But this is a very broad question with a broad answer. You haven't answered my question as to what file types you intend to display. Writing a program that properly displays files of any random type is going to be hard if not impossible. And I wouldn't know why you would want to do that. What is the ultimate purpose if the program you are developing?
-
Jul 30th, 2020, 12:31 AM
#8
Thread Starter
New Member
Re: How to copy text from some internet document to RichTextBox?
OK. It seems it is impossible. At least, in an easy way.
Thanks for your help.
-
Jul 30th, 2020, 02:42 AM
#9
Re: How to copy text from some internet document to RichTextBox?
Okay. You’re welcome. But what were you trying to do?
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
|