日期:2014-05-18  浏览次数:20869 次

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