SoFunction
Updated on 2025-03-06

How to remotely read text content on a server in C#

C# remotely read text content on the server

WebClient client = new WebClient();
byte[] buffer = (":8888/");
string res = ("GB2312").GetString(buffer);
//string res = (buffer);
 = res;

C# Text Reading and Saving

private void btSave_Click(object sender, EventArgs e)  //Save txt file{
                 = ("Text file(*.txt)|*.txt");  //Create a filter                if (() == )  //Judge whether to save or cancel the pressed                {
                    string path = ;  //Get file name and path                    using (StreamWriter sw = new StreamWriter(path, false))  //Save the file to the specified path                    {
                        ();
                    }
}
 

private void btOpen_Click(object sender, EventArgs e)  //Open txt file{
             = ("Text file(*.txt)|*.txt");  //Create a filter            if (() == )  //Judge whether the pressed to turn on or cancel            {
                string path = ;  //Get file name and path                using (StreamReader sr = new StreamReader(path, Encoding.UTF8))  //Open the file                {
                     = ();
                }
            }
}

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.