Answer the question
In order to leave comments, you need to log in
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
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();
byte[] content=File.ReadAllBytes(@"C:\ServiceLog.txt");
File.WriteAllBytes(@"C:\12.txt",content);
// using System.IO;
string filepath = @"C:\test.txt";
using (StreamWriter writer = new StreamWriter(filepath)){
writer.WriteLine("some text");
}
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 questionAsk a Question
731 491 924 answers to any question