Passing a function in an anchor within a console vb.net - vb.net

please how can i pass a link with function which take an id from a function please
Dim Email As String = "ultimadan#hotmail.com"
Dim msgBody As New StringBuilder()
msgBody.Append("Thank you, please click the link below.")
msgBody.Append("<a href=http://localhost:49789/Seller/Part1/Default.aspx?" & GetUserID(Email))

It looks like you're just not building the complete anchor tag. You're missing a key for the query string value, you're not closing the tag, etc. Your current code might produce something like:
<a href=http://localhost:49789/Seller/Part1/Default.aspx?123
Which isn't complete or valid HTML. Did you mean something more like this?:
msgBody.Append(
"<a href=""http://localhost:49789/Seller/Part1/Default.aspx?userid="
& GetUserID(Email)
& """>click here</a>"
)
Which should produce something more like:
click here

Related

Open jquery ui dialog from itemcommand

I'd like to be able to display iframe content in Jquery UI dialog and not a pop up as I'm currently doing, but I can't seem to find a way of getting this accomplished.
My current solution looks like this:
If e.CommandName = "CustIDCommand" Then
Dim CustIDButton As LinkButton
CustIDButton = FindControl("CustIDBtn")
Dim str As String = "<script language='Javascript'>"
str = str + "window.open('/secure/CustCC.aspx','newwin','location=no,toolbar=no,menubar=no,width=500,height=275,left=400,top=300')"
str = str + "</script>"
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "win", str)
Session("CustID") = e.CommandArgument
End If
An ID number is passed so the CustCC.aspx page displays the correct data. All works fine, but I'd like to load this page in a modal and not a pop up.
Any help greatly appreciated
Do something like this:
$("#somediv").load(url).dialog({modal:true});
https://jqueryui.com/dialog/

Get filename of current RDLC report

I need to get the filename of the current RDLC being displayed on the ReportViewer. Is there something like
Dim filename As String = Me.ReportViewer1.LocalReport.GetFilename?
because I do not want to do the following.
Dim path As String() = Me.ReportViewer1.LocalReport.ReportPath.Split("\")
Dim filename As String = path(path.Length - 1)
There doesn't seem to be any members in the ReportViewer or its LocalReport property to enable you to do this.
However, you might be able use a method like Path.GetFileName to do something like:
Dim filename As String = Path.GetFileName(Me.ReportViewer1.LocalReport.ReportPath)
So you're not doing the string split operation etc.
I completely agree with NKVU's answer and additionally, If you want to get the filename without its extension, You can use this,
Path.GetFileNameWithoutExtension(Me.ReportViewer1.LocalReport.ReportPath)

How to Post & Retrieve Data from Website

I am working with a Windows form application. I have a textbox called "tbPhoneNumber" which contains a phone number.
I want to go on the website http://canada411.com and enter in the number that was in my textbox, into the website textbox ID: "c411PeopleReverseWhat" and then somehow send a click on "Find" (which is an input belonging to class "c411ButtonImg").
After that, I want to retrieve what is in between the asterixs of the following HTML section:
<div id="contact" class="vcard">
<span><h1 class="fn c411ListedName">**Full Name**</h1></span>
<span class="c411Phone">**(###)-###-####**</span>
<span class="c411Address">**Address**</span>
<span class="adr">
<span class="locality">**City**</span>
<span class="region">**Province**</span>
<span class="postal-code">**L#L#L#**</span>
</span>
So basically I am trying to send data into an input box, click the input button and store the values retrieved into variables. I want to do this seemlessly so I would need to do something like an HTTPWebRequest? Or do I use a WebBrowser object? I just don't want the user to see that the application is going on a website.
I do a good amount of website scraping and I will show you how I do it. Feel free to skip ahead if I am being too specific, but this is a commonly requested theme and should be made specific.
URL Simplification
The library I use for this is htmlagilitypack (It is a dll, make a new project and add a reference to it). The first thing to check is if we have to go to take any special steps to get to a page by using a phone number. I searched for John Smith and found quite a few. I entered 2 of these results and noticed that the url formatting is very simple. Those results were..
http://www.canada411.ca/res/7056736767/John-Smith/138223109.html
http://www.canada411.ca/res/7052355273/John-Smith/172439951.html
I tested to see if I can remove some of the values from the url that I don't know and just leave the phone number. The result was that I can...
http://www.canada411.ca/search/re/1/7056736767/-
http://www.canada411.ca/search/re/1/7052355273/-
You can see by the url that there are some static areas in the url and our phone number. From this lets construct a string for the url.
Dim phoneNumber as string = "7056736767" 'this could be TextBox1.Text or whatever
Dim URL as string = "http://www.canada411.ca/search/re/1/" + phoneNumber +"/-"
Value Extraction with XPath
Now that we have the page dialed in, lets examine the html you provided above. You need 6 values from the page so we will create them now...
Dim FullName As String
Dim Phone As String
Dim Address As String
Dim Locality As String
Dim Region As String
Dim PostalCode As String
As mentioned above, we will be using htmlagilitypack which uses Xpath. The cool thing about this is that once we can find some unique identifier in the html, we can use Xpath to find our values. I know it may be confusing, but it will become clearer.
All of the values you need are within tags that have a class name. Lets use the class name in our Xpath to find them.
Dim FullNameXPath As String = "//*[#class='fn c411ListedName']"
Dim PhoneXPath As String = "//*[#class='c411Phone']"
Dim AddressXPath As String = "//*[#class='c411Address']"
Dim LocalityXPath As String = "//*[#class='locality']"
Dim RegionXPath As String = "//*[#class='region']"
Dim PostalCodeXPath As String = "//*[#class='postal-code']"
Essentially what we are looking at is a string that will inform htmlagilitypack what to look for. In our case, text contained within the classes we named. There is a lot to XPath and it could take a while to explain all of it. On a side note though...If you use Google Chrome and highlight a value on a page, you can right click inspect element. In the code that appears below, you can right click the value and copy to XPath!!! Very useful.
Basic HTMLAgilityPack Template
Now, all that is left is to connect to the page and get those variables populated.
Dim Web As New HtmlAgilityPack.HtmlWeb
Dim Doc As New HtmlAgilityPack.HtmlDocument
Doc = Web.Load(URL)
For Each nameResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(FullNameXPath)
Msgbox(nameResult.InnerText)
Next
In the above example we create an HtmlWeb object named Web. This is the actual crawler of our project. We then define a HtmlDocument which will consist of our converted and searchable page source. All of this is done behind the scenes. We then send Web to get the page source and assign it to the Doc object we created. Doc is reusable, which thankfully requires us to connect to the page only once.
The for loop looks for any nodes in our Doc that match FullNameXPath which was defined previously as the XPath value for finding the name. When a Node is found, it is assigned to the nameResult variable and from within the loop we call a message box to display the inner text of our node.
So when we put it all together
Complete Working Code (As of 2/17/2013)
Dim phoneNumber As String = "7056736767" 'this could be TextBox1.Text or whatever
Dim URL As String = "http://www.canada411.ca/search/re/1/" + phoneNumber + "/-"
Dim FullName As String
Dim Phone As String
Dim Address As String
Dim Locality As String
Dim Region As String
Dim PostalCode As String
Dim FullNameXPath As String = "//*[#class='fn c411ListedName']"
Dim PhoneXPath As String = "//*[#class='c411Phone']"
Dim AddressXPath As String = "//*[#class='c411Address']"
Dim LocalityXPath As String = "//*[#class='locality']"
Dim RegionXPath As String = "//*[#class='region']"
Dim PostalCodeXPath As String = "//*[#class='postal-code']"
Dim Web As New HtmlAgilityPack.HtmlWeb
Dim Doc As New HtmlAgilityPack.HtmlDocument
Doc = Web.Load(URL)
For Each nameResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(FullNameXPath)
FullName = nameResult.InnerText
MsgBox(FullName)
Next
For Each PhoneResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(PhoneXPath)
Phone = PhoneResult.InnerText
MsgBox(Phone)
Next
For Each ADDRResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(AddressXPath)
Address = ADDRResult.InnerText
MsgBox(Address)
Next
For Each LocalResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(LocalityXPath)
Locality = LocalResult.InnerText
MsgBox(Locality)
Next
For Each RegionResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(RegionXPath)
Region = RegionResult.InnerText
MsgBox(Region)
Next
For Each postalCodeResult As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes(PostalCodeXPath)
PostalCode = postalCodeResult.InnerText
MsgBox(PostalCode)
Next
Yes it is possible, I've done this using the selenium framework, which is aimed for testing automation. However, it provides you with the tools to do exactly that.
Download for .net here:
http://docs.seleniumhq.org/download/

How do I search through a string for a particular hyperlink in Visualbasic.net?

I have a written a program which downloads a webpage's source but now I want to search the source for a particular link I know the link is written like this:
<b>Geographical Survey Work</b>
Is there anyway of using "Geographical Survey Work" as criteria to retrieve the link? The code I am using to download the source to a string is this:
Dim sourcecode As String = ((New Net.WebClient).DownloadString("http://examplesite.com"))
So just to clarify I want to type into an input box "Geographical Survey Work" for instance and "/internet/A2" to popup in a messagebox? I think it can be done using a regex, but that's a bit beyond me. Any help would be great.
With HTMLAgilityPack:
Dim vsPageHTML As String = "<html>... your webpage HTML code ...</html>"
Dim voHTMLDoc.LoadHtml(vsPageHTML) : vsPageHTML = ""
Dim vsURI As String = ""
Dim voNodes As HtmlAgilityPack.HtmlNodeCollection = voHTMLDoc.SelectNodes("//a[#href]")
If Not IsNothing(voNodes) Then
For Each voNode As HtmlAgilityPack.HtmlNode In voNodes
If voNode.innerHTML.toLower() = "<b>geographical survey work</b>" Then
vsURI = voNode.GetAttributeValue("href", "")
Exit For
End If
Next
End If
voNodes = Nothing : voHTMLDoc = Nothing
Do whatever you want with vsURI.
You might need to tweak the code a bit as I'm writing free-hand.

link is getting truncated, any ideas why?

I have been making some progress on this but still have some issues to resolve.
Hopefully, this one won't be that hard.
I have this:
For Each item In Request.QueryString("doc").Split(","c)
sb.Append("http://default.html?k=")
sb.Append(item)
sb.Append("&p=2&o=m</p>")
Next
When I test this code:
Response.Write(sb.ToString())
I get:
http://default.html?k=122&p=2&o=m
http://default.html?k=123&p=2&o=m
That's exactly what we are looking for
When we assign it to a variable like:
Dim linkList As String = sb.ToString()
However, when I loop through linkList
and write it to the screen, it is spitting out only the letter h.
Any ideas what I am doing wrong and how to fix it if possible?
Dim link As String
For Each link I linkList
'let me know if I am still getting the links
response.write link
'we will save all the links later
Next
As always, thanks a lot for your help
You can not loop through a string and get another string (note: linkList is a String - Dim linkList As String = sb.ToString()). That's why you get the h it's trying to pick the Chars in the string. Place the strings in an array then loop through the array. Try this:
Dim linkArray() As String
For Each item In Request.QueryString("doc").Split(","c)
Dim stb As New StringBuilder
stb.Append("http://default.html?k=")
stb.Append(item)
stb.Append("&p=2&o=m</p>")
linkArray.add(stb.toString())
Next
For Each link As String In linkArray
response.write link
Next
It looks like you are not closing your <a> tag
&p=2&o=m</p>
Notice the </p> to close a paragraph without the closing <a> tag with </a>.
Try to view source and you'll probably see the HTML is malformed in that way.