我創建了一個類庫,現在我想在網站上使用它。在我的網站上使用類庫C#
using System;
using System.Web.UI;
namespace FeedPath
{
public partial class ClassFeed : System.Web.UI.Page
{
public void ParseFeed(string builtUrl, int maxFeed, string code)
{
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(builtUrl);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rstream = myResponse.GetResponseStream();
System.Xml.XmlDocument rdoc = new System.Xml.XmlDocument();
rdoc.Load(rstream);
System.Xml.XmlNodeList ritems = rdoc.SelectNodes("rss/channel/item");
string title = "", link = "", sdescription = "";
string staticstring = code;
for (int i = 0; i < maxFeed; i++)
{
staticstring = staticstring + i;
System.Xml.XmlNode rdetail;
title = "";
link = "";
sdescription = "";
rdetail = ritems.Item(i).SelectSingleNode("title");
if (rdetail != null)
{
title = rdetail.InnerText;
}
rdetail = ritems.Item(i).SelectSingleNode("link");
if (rdetail != null)
{
link = rdetail.InnerText;
}
rdetail = ritems.Item(i).SelectSingleNode("description");
if (rdetail != null)
{
sdescription = rdetail.InnerText;
}
Response.Write("<li id='" + staticstring + "'><h3><a href='" + link + "' target='new'>" + title + "</a></h3>" + sdescription + "</li>");
staticstring = code;
}
}
}
}
然後在我的.aspx使用
<% string fd01Url = "https://bitly.com/u/l3ny.rss"; ParseFeed(fd01Url, 7, "bl"); %>
我加了參考,但現在我無法對其進行初始化。
我想:
using FeedPath;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FeedPath.ClassFeed Myopject = new.FeedPath();
}
}
,但沒有運氣。
下面的圖像是我提出的類:
歡迎來到Stack Overflow。有幾件事情可以確保你提出很好的問題:在問題本身中包含實際的代碼。這意味着作爲一種資源來幫助每個人,而不僅僅是你。您的圖片可能無法提供給此問題的未來觀衆。您還需要顯示所有相關代碼,而不僅僅是一小段代碼。請編輯您的問題以提供此信息。 – mason
您的「類庫」包含一個從Page繼承的類。爲什麼? – sh1rts
我想我沒有把所有的代碼。我的錯。 @ sh1rts我是新手我不知道,但我想因爲我使用<%string fd01Url =「https://bitly.com/u/l3ny.rss」; ParseFeed(fd01Url,7,「bl」); %>在abc.aspx頁面上?不知道,謝謝。 – l3ny