首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么读取http text file

2012-01-13 
如何读取http text file?http://localhost/test/myfile.txt如何读取這個text file?[解决办法]stirng path

如何读取http text file?
http://localhost/test/myfile.txt
如何读取這個text file?



[解决办法]
stirng path = HttpContext.Current.Server.MapPath(@"~\test\myfile.txt")

StreamReader sr = new StreamReader(path,System.Text.Encoding.GetEncoding("GB2312"));

sline = sr.ReadToEnd();
sr.Close();
[解决办法]

C# code
using System.Net; WebClient wc = new WebClient(); string webstr = "";            try            {                webstr = System.Text.Encoding.Default.GetString(wc.DownloadData(url));            }            catch (Exception ee)            {                MessageBox.Show("错误!" + ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                RemoveStatus();                return;            } 

热点排行