S
S
sidor_tank2019-03-15 17:35:17
API
sidor_tank, 2019-03-15 17:35:17

How to save a file received via API in the previous received format?

Good day to all, I have a problem, I want to save the file received via the API from the github, but I don’t know how to implement it in C#. I would like to see code examples in the answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy Orlov, 2019-03-15
@sidor_tank

I would also like to see a code example in the question.
You can save a file in C# like this

byte[] content=File.ReadAllBytes(@"C:\ServiceLog.txt");
FileStream stream = new FileStream(@"C:\ServiceLog1.txt", FileMode.Create, FileAccess.ReadWrite);
stream.Write(content, 0, content.Length);
stream.Close();

or so
byte[] content=File.ReadAllBytes(@"C:\ServiceLog.txt");
File.WriteAllBytes(@"C:\12.txt",content);

or so
// using System.IO;
string filepath = @"C:\test.txt";
using (StreamWriter writer = new StreamWriter(filepath)){
    writer.WriteLine("some text");
}

S
sidor_tank, 2019-03-15
@sidor_tank

I did this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_F + "&path=" + textBox1.Text);
                try
                {
                    WebResponse response = request.GetResponse();
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        //SaveFileDialog dlg = new SaveFileDialog();
                        //dlg.ShowDialog();
                        //dlg.Filter = "Rich Text Format (*.rtf)|*.rtf|All files (*.*)|*.*";

                        using (StreamWriter sw = new StreamWriter("Poyasnitelnaya_zapiska.docx", false, System.Text.Encoding.Default))
                        {
                            sw.Write(reader.ReadToEnd());
                        }
                        MessageBox.Show("Download comlite");
                    }
                }
the result is a source file that cannot be opened by Word, but I need to get a working copy of the downloaded file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question