日期:2014-01-23 浏览次数:20957 次
核心代码如下:
(用webRequest得到指定页的内容,然后用FileStream写到本地文件中)
核心部份(下载RSS链接的XML文件到本地!)
private void download_Click(object sender, System.EventArgs e)
{
Encoding sjis = Encoding.GetEncoding("utf-8");
FileStream fs = new FileStream(Server.MapPath(".")+"\\sina.xml",FileMode.Create,FileAccess.Write);
//建立StreamWriter为写做准备
StreamWriter rw = new StreamWriter(fs,sjis);
string rl;
//创建WebRequest对象
WebRequest myReq = WebRequest.Create("http://rss.sina.com.cn/news/marquee/ddt.xml");//读取远程文件(新浪新闻),然后用FileStream将文件保存到本地!
//创建WebResponse对象
WebResponse myRes = myReq.GetResponse();
//获取Stream
Stream resStream = myRes.GetResponseStream();
//以下操作为读取Stream对象中的内容
StreamReader sr = new StreamReader(resStream,sjis);
StringBuilder sb = new StringBuilder();
while((rl=sr.ReadLine())!=null)
{<