Load a URL's execution result

  • Thread starter Thread starter stevag
  • Start date Start date
S

stevag

Hello,

I am developing an application whose main goal is to read from a dynamic
..asp Internet URL. This URL automatically produces an RSS file, which I
further want to load into my application so as to manilupate the source
and render the results into an HTML page using ASP.NET and C#.
My problem is how (which classes and methods of ASP.NET in C# do I use)
do I read this .asp page and import the produced .rss file into my
XmlDocument in the Page_Load ( ) event.

=============================================================================================================================
This is what I have implemented so far, but it doesnt work unless the
feedURL is read directly from a local static file.


public class DisplayRSS : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Xml MyXMLWebControl;
string feedURL="test.rss"; /* But in the real case I want to
read from
the dynamic .asp file that produces the .rss file */

private void Page_Load(object sender, System.EventArgs e)
{
XmlDocument mylist = new XmlDocument();
mylist.Load(feedURL);
MyXMLWebControl.Document = mylist;

/*Here I move on with setting the properties for the associated XLST for
parsing the rss file and rendering the results on my ASP.NET page */

}
}

=============================================================================================================================
Any help and ideas on this would be more than welcome.


stevag
 
string feedURL="test.rss"; /* But in the real case I want to
read from
the dynamic .asp file that produces the .rss file */
Here's a simple way to read the results from an URL:

using System.Net;
using System.Xml;

// Set up the request to the server
HttpWebRequest myRequest =
(HttpWebRequest)HttpWebRequest.Create("http://www.yahoo.com");
myRequest.Method = "GET";

// Read the response from the server
HttpWebResponse myResponse = (HttpWebResponse) myRequest.GetResponse();
StreamReader read = new StreamReader(myResponse.GetResponseStream());
string sXML = read.ReadToEnd();
myResponse.Close();

// Process the answer from the server
XmlDocument xmlDoc = new XmlDocument();
// Expect an expection here: yahoo.com doesn't return an XML document.
xmlDoc.LoadXml( sXML );

Greetings,
Wessel
 
If URL is hosted on your server, u can use Server.Execute, otherwise u
should use HttpWebRequest as Wessel pointed out..

--
HTH

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
 
Back
Top