RSS Aggregator
-
Hi, I'm trying to create a RSS News Aggregator, and this is part of code for it:
private void Page_Load(object sender, System.EventArgs e) { // See if the news items for this feed are in the Data Cache string strFeedID = Request.QueryString["FeedID"]; int feedID = 0; if (strFeedID != null) { feedID = Int32.Parse(strFeedID); } XmlDocument feedXML = (XmlDocument) Cache["Feed" + feedID]; if (feedXML == null) { // item not found in cache, get the feed details // Connect to the Database OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\SyndicationDemo\\RSS.mdb"); // Retrieve the SQL query results string SQL_QUERY = "SELECT URL, UpdateInterval FROM Feeds WHERE FeedID = @FeedID"; OleDbCommand myCommand = new OleDbCommand(SQL_QUERY, myConnection); OleDbParameter feedParam = new OleDbParameter("@FeedID", OleDbType.Integer, 4); feedParam.Value = feedID; myCommand.Parameters.Add(feedParam); myConnection.Open(); string feedURL = ""; int updateInterval = 0; OleDbDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); reader.Read(); try { feedURL = reader["URL"].ToString(); updateInterval = Int32.Parse(reader["UpdateInterval"].ToString()); } catch { feedURL = "default url"; updateInterval = 0; // or any other default value } myConnection.Close(); // Now that we have the feed URL, load it in into an XML document feedXML = new XmlDocument(); feedXML.Load(feedURL); Cache.Insert("Feed" + feedID, feedXML, null, DateTime.Now.AddMinutes(updateInterval), TimeSpan.Zero); } xmlNewsItems.Document = feedXML; // Add the FeedID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("FeedID", "", feedID); xmlNewsItems.TransformArgumentList = xsltArgList; }
____________________________________________________ I am receiving this error when I tr -
Hi, I'm trying to create a RSS News Aggregator, and this is part of code for it:
private void Page_Load(object sender, System.EventArgs e) { // See if the news items for this feed are in the Data Cache string strFeedID = Request.QueryString["FeedID"]; int feedID = 0; if (strFeedID != null) { feedID = Int32.Parse(strFeedID); } XmlDocument feedXML = (XmlDocument) Cache["Feed" + feedID]; if (feedXML == null) { // item not found in cache, get the feed details // Connect to the Database OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\SyndicationDemo\\RSS.mdb"); // Retrieve the SQL query results string SQL_QUERY = "SELECT URL, UpdateInterval FROM Feeds WHERE FeedID = @FeedID"; OleDbCommand myCommand = new OleDbCommand(SQL_QUERY, myConnection); OleDbParameter feedParam = new OleDbParameter("@FeedID", OleDbType.Integer, 4); feedParam.Value = feedID; myCommand.Parameters.Add(feedParam); myConnection.Open(); string feedURL = ""; int updateInterval = 0; OleDbDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); reader.Read(); try { feedURL = reader["URL"].ToString(); updateInterval = Int32.Parse(reader["UpdateInterval"].ToString()); } catch { feedURL = "default url"; updateInterval = 0; // or any other default value } myConnection.Close(); // Now that we have the feed URL, load it in into an XML document feedXML = new XmlDocument(); feedXML.Load(feedURL); Cache.Insert("Feed" + feedID, feedXML, null, DateTime.Now.AddMinutes(updateInterval), TimeSpan.Zero); } xmlNewsItems.Document = feedXML; // Add the FeedID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("FeedID", "", feedID); xmlNewsItems.TransformArgumentList = xsltArgList; }
____________________________________________________ I am receiving this error when I trThe exception is pretty obvious: the path you're requesting can't be found. When you want to load a file, you must use the physical path - not the URL. In ASP.NET, you can use
MapPath
(implemented on thePage
andHttpServerUtility
(theServer
property that many classes expose)) to map a virtual path (i.e., URL) to a physical path on the same machine:feedURL = MapPath("default url");
That'll get you the physical path to the file which you can load into your
XmlDocument
.Microsoft MVP, Visual C# My Articles
-
The exception is pretty obvious: the path you're requesting can't be found. When you want to load a file, you must use the physical path - not the URL. In ASP.NET, you can use
MapPath
(implemented on thePage
andHttpServerUtility
(theServer
property that many classes expose)) to map a virtual path (i.e., URL) to a physical path on the same machine:feedURL = MapPath("default url");
That'll get you the physical path to the file which you can load into your
XmlDocument
.Microsoft MVP, Visual C# My Articles
-
Hi, Thanks for your feedback. This section of the aggregator should initially display a blank page, and not anything else (including any other URL's). Do you know how I could go about rectifying that? Thanks once again :)
1. Set all controls'
Visible
properties tofalse
that you don't want displayed. 2. OverrideRender
in your page and don't render anything initially. 3. Redirect to a blank page. 4. Transfer execution to a blank page. 5. ... There's countless ways.Microsoft MVP, Visual C# My Articles
-
1. Set all controls'
Visible
properties tofalse
that you don't want displayed. 2. OverrideRender
in your page and don't render anything initially. 3. Redirect to a blank page. 4. Transfer execution to a blank page. 5. ... There's countless ways.Microsoft MVP, Visual C# My Articles