Downloading the elements of a Webpage as String in VB.Net - vb.net

I am using VS 2019 and developing a winform applicaion using VB.Net.
I want to get the elements of a webpage into a string so that I can extract
the required value from that string.
The following are my Imports -
Imports System.IO
Imports System.Net
I had put a button on a form for initiating the process. As I was debugging the function, when it came to the line "Dim response As HttpWebResponse = request.GetResponse()" it just loads the form back and does not proceed to the next line.
May I seek help on this? Thanks in advance.
I went through Download contents of webpage with VB and tried to implement the answer given.
I also prefixed the request and response with "Net." as mentioned there. But still the results are same.

Related

Including source files at compile time with Visual Studio

As usual, I do my research in the various forums. My personal discipline is that if I have struggled for more than a day, I need to reach out for help. Because after a day, I can no longer see the wood because of the trees.
My web site has some code written in VB.NET which I use on many pages of the web site. Where possible, I try to write code only once. For obvious reasons. I include the code in a class. However, when I use a class, I cannot access the page controls. For example, the HTTP context is available on the VB.NET code-behind but not in the class declared in the code-behind. Is there some way of achieving this result?
Another option is to have VB.NET code in a separate source file. And to include this source file into the main source code file at compile time. If I need to make a change, I can do it in the source code “segment” once only. Right now, if I want to make a global change, I have to cut and paste through many web pages. I have read that this type of “include” was possible in VB prior to VB.NET. I can find no reference to this for VB.NET in Visual Studio. Any suggestions?
For example if this code is to be run on every web page, how would you set it up so that you only have one source? That is called on 150 pages?
Protected Sub getCookieVariable()
'
Dim myCookieName As String
Dim myCookieValue As String
'
myCookieName = "hfl3"
Dim myCookie As HttpCookie = HttpContext.Current.Request.Cookies(myCookieName)
If Request.Cookies(myCookieName) IsNot Nothing Then
myCookieValue = myCookie.Value
myCookie.Expires = DateTime.Now.AddDays(30)
Response.Cookies.Add(myCookie)
session("myCookieValue") = myCookieValue
End If
'
End Sub

Including source files at compile time with VB.NET and Visual Studio

As usual, I do my research in the various forums. My personal discipline is that if I have struggled for more than a day, I need to reach out for help. Because after a day, I can no longer see the wood because of the trees.
My web site has some code written in VB.NET which I use on many pages of the web site. Where possible, I try to write code only once. For obvious reasons. I include the code in a class.
However, when I use a class, I cannot access the page controls. For example, the HTTP context is available on the VB.NET code-behind but not in the class declared in the code-behind. Is there some way of achieving this result?
Another option is to have VB.NET code in a separate source file. And to include this source file into the main source code file at compile time. If I need to make a change, I can do it in the source code
“segment” once only. Right now, if I want to make a global change, I have to cut and paste through many web pages. I have read that this type of “include” was possible in VB prior to VB.NET. I can find no reference to this for VB.NET in Visual Studio. Any suggestions?
For example if this code is to be run on every web page, how would you set it up so that you only have one source? That is called on 150 pages?
Protected Sub getCookieVariable()
'
Dim myCookieName As String
Dim myCookieValue As String
'
myCookieName = "hfl3"
Dim myCookie As HttpCookie = HttpContext.Current.Request.Cookies(myCookieName)
If Request.Cookies(myCookieName) IsNot Nothing Then
myCookieValue = myCookie.Value
myCookie.Expires = DateTime.Now.AddDays(30)
Response.Cookies.Add(myCookie)
session("myCookieValue") = myCookieValue
End If
'
End Sub

pass value to a web browser and print it in a particular textbox

I have a win-form application that generates passwords that I would like to send directly over to a web page textbox like input as apart of a new user sign up. I found a similair question. (Fill Form C# & Post Error) But I dont think I am after the same goal. Is it possible to do this without using a macro or manually copy n pasting? The above post is in C# however I will ever using vb. If there is a answer on here please link, but I have gone through the forum.

How to submit error reports to developer?

How can I submit error reports to the developer (me) when coding in VB.NET?
I have made a Google Forms response form here. Is it possible to use the WebBrowser Control functions to paste a string into the TextBox in there and then click the button to submit it, all automatically?
Would it be better to use a different submission form service than this? I know that it uses complicated JavaScript to code everything. If it would be better to use a custom HTML website, how would you interact with that (I can probably figure out how to code the HTML itself)?
All help welcome!
OK, this was my solution: use System.Net.Mail and MailMessage and SMTP Credentials to send an email to the developer.

Public properties from another class in vb.net

I've tried searching... a lot for the answer, but as I'm not too sure what exactly I'm trying to do I can't seem to find anything.
I'm trying to write a dll in order to handle errors thrown from a vb.net app. In the dll I need several forms (I'm not totally sure if they can have forms - I'm a bit of a newbie when it comes to dll's) for which the user can type in their message about the error and submit it.
I need to be able to pass strings to the form and for the form to be able to access public subs in the class file.
For instance I have a public sub called Emailer, which I want, when the submit button is clicked from the form to be run.
Or, lets say I have a public string:
Public strName as string = nothing
why cant I, from the class file just do this:
frmFormName.strName = "abc"
Not sure if I've explained that very well, but like I said I'm a bit of a newbie with this stuff.
1) You can have froms in a DLL it just does not have a entry point you will need a exe for this this. Which it sounds like you have
2) You will need to add a project reference to a dll from your exe
ok not sure how this will work but try to download this Example project let me know if you have more questions