-2

I am familiar with ASP.NET, but not with Visual Basic.

Here is the Visual Basic code:

 myxml="http://api.ipinfodb.com/v3/ip-city/?key="&api_key&"&ip=" &UserIPAddress&"&format=xml"
 set xml = server.CreateObject("MSXML2.DOMDocument.6.0")
 xml.async = "false"
 xml.resolveExternals = "false"
 xml.setProperty "ServerHTTPRequest", true
 xml.load(myxml)
 response.write "<p><strong>First result</strong><br />"
 for i=0 to 10
     response.write xml.documentElement.childNodes(i).nodename & "  :  "
     response.write xml.documentElement.childNodes(i).text & "<br/>"
 NEXT
 response.write "</p>"

What is going on in this code?

How can I convert this to ASP.NET (C#)?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Blu
  • 4,036
  • 6
  • 38
  • 65
  • What does this code actually *do*? You generally don't want to perform a direct conversion from one language to another, or one framework or paradigm to another. Instead, you want to implement the desired functionality in the target environment. What is the resulting functionality here that you want to achieve? – David Aug 08 '13 at 01:23
  • Hi @David i get this example from this site http://ipinfodb.com/ip_location_api.php here it is in VB form but i dont understand it i want little help on this i need it in ASPX.Net – Blu Aug 08 '13 at 01:25
  • So it looks to me like this code is going out to a URL (`api.ipinfodb.com`) and loading XML, then it is looping through the first 10 child nodes of the root of the XML document and putting the node name and text into a paragraph tag that gets put into the DOM of a webpage. – Karl Anderson Aug 08 '13 at 01:28
  • @user2651088: Not to sound unconstructive, but if you don't know what the code is intended to do then why do you need it? What functionality are you intending to implement? Are you just randomly adding code to your application that you find online, or are you actually trying to implement specific functionality? – David Aug 08 '13 at 01:29
  • yes @KarlAnderson it is now how i do in ASPX.Net? ANy hint or suggestion i dont need full code – Blu Aug 08 '13 at 01:30
  • @David i am doing that "If i put any IP Address of server it gives me the Coordinates of that server" – Blu Aug 08 '13 at 01:32

2 Answers2

2

Based on a quick glance at the site you linked to in a comment, it looks like the intended functionality is to make a request to a URL and receive the response. The first example given on that site is:

http://api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&ip=74.125.45.100

You can probably use something like the System.Net.WebClient object to make an HTTP request and receive the response. The example on MSDN can be modified for your URL. Maybe something like this:

var client = new WebClient();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
var data = client.OpenRead(@"http://api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&ip=74.125.45.100");
var reader = new StreamReader(data);
var result = reader.ReadToEnd();
data.Close();
reader.Close();

(There's also the WebRequest class, which appears to share roughly the same functionality.)

At that point the result variable contains the response from the API. Which you can handle however you need to.

David
  • 208,112
  • 36
  • 198
  • 279
1

From the looks of the Visual Basic code, I think you should create two methods to "convert" this to an ASP.NET C# web page:

  1. LoadXmlData method - use an XmlDocument to load from the URL via the XmlDocument's Load function. Read ASP.net load XML file from URL for an example.

  2. BuildDisplay method - use an ASP.NET PlaceHolder or Panel to create a container to inject the paragraph tag and individual results into.

Community
  • 1
  • 1
Karl Anderson
  • 34,606
  • 12
  • 65
  • 80