Saturday, March 24, 2012

Please Help how do I Microsoft.XMLHTTP in .net

I am using the following code to parse a .txt file from a remote server using asp

set xml1 = CreateObject("Microsoft.XMLHTTP")
xml1.Open "GET", strURL, False
xml1.send
strXmlContents = xml1.responseText

how do I do this in .aspx?with the HTTPWebRequest class. here :

http://rtfm.atrax.co.uk/infinitemonkeys/articles/asp.net/990h.asp
That looks really nice for an advanced programer but I am completly lost. Is that in c#?

<%@. import namespace="System.Net" %>
WebClient objClient = new WebClient();
private void Page_Load(Object o, EventArgs e){
WebClient objClient = new WebClient();
}

private void Page_Load(Object o, EventArgs e){
WebClient objClient = new WebClient();
Stream objStream = objClient.OpenRead("http://lycosa/default.asp");
}

Is this all I need? what do I save this as?
> Is this all I need?

not quite. this is the code you need, sure, but you need to fill in a few bits round it. I take it you're a raw novice then?
I think I got thst part

<%@. import namespace="System.IO" %>
<%@. Control Language="vb" debug="true" Codebehind="Live Lines.ascx.vb" %>
<HTML>
<HEAD>
<title>Messing around with ASP.NET in VB</title>
</HEAD>
<body>
<script language="VB" runat="server"
Public Sub Page_Load()
Dim fileName as String
fileName = "C:\schedule.txt"
Dim strmR as StreamReader = File.OpenText(fileName)
lblStart.Text = Server.HtmlEncode(strmR.ReadToEnd()).Replace(vbcrlf, "<br />")
strmR.Close()
End Sub

</script>
<asp:label runat="server" id="lblStart" font-name="verdana" />
</body>
</HTML
This seems to work for me. 2 questions

1. How can I change this fileName = "C:\schedule.txt" for non local files? Like this, fileName = "http://blah/schedule.txt" ?
2. My information is now displayed like this
1| 1|20030915|18:05|DALLAS |219| 37|
1| 1|20030915|18:05|NY GIANTS |220| 7|

How do I convert this to xml and display it if I know the name for each category?
Yes I am a super nooob
Anyone have a suggestion?
You're going to need to split the delimited file first at the linebreaks, then at the pipe characters (|), then you'll be able to loop through the resulting arrays and stick them in an XML document.

I'll scout around and see if there's a tutorial on it somewhere, but equally there may be a library for this task on this very site...

0 comments:

Post a Comment