-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#)?

6
  • 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? Commented Aug 8, 2013 at 1:23
  • Hi @David i get this example from this site 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 Commented Aug 8, 2013 at 1: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. Commented Aug 8, 2013 at 1: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? Commented Aug 8, 2013 at 1:29
  • yes @KarlAnderson it is now how i do in ASPX.Net? ANy hint or suggestion i dont need full code Commented Aug 8, 2013 at 1:30

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.