How to read a file from internet?

后端 未结 7 1915
甜味超标
甜味超标 2020-12-03 03:05

simple question: I have an file online (txt). How to read it and check if its there? (C#.net 2.0)

7条回答
  •  甜味超标
    2020-12-03 03:31

    I think the WebClient-class is appropriate for that:  

    WebClient client = new WebClient();
    Stream stream = client.OpenRead("http://yoururl/test.txt");
    StreamReader reader = new StreamReader(stream);
    String content = reader.ReadToEnd();
    

    http://msdn.microsoft.com/en-us/library/system.net.webclient.openread.aspx

提交回复
热议问题