读书人

怎么读取http text file

发布时间: 2012-01-13 22:43:29 作者: rapoo

如何读取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;            } 

读书人网 >C#

热点推荐