I am a maker in programming, so I ask the question how best to do it: you need to select a file on the computer, perform some actions with it (for example, encrypt it), and then save it. The only thing I did was open the file via OpenFileDialog (at the touch of a button). Please do not throw slippers, if I ask the simplest questions - I do not understand)
|
1 answer
Suppose you got the name of the file to read it.
OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { string filename = openFileDialog.FileName; } Next, there are options. For example, you can read the contents in a MemoryStream to work with it in RAM:
using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(filename))) { // Делаем что-то важное } Then after the necessary transformations save it:
using (FileStream fileStream = new FileStream("Какое_то_имя_файла.расширение", FileMode.Create, FileAccess.Write)) { byte[] bytes = new byte[memoryStream.Length]; memoryStream.Read(bytes, 0, (int)memoryStream.Length); fileStream.Write(bytes, 0, bytes.Length); } - oneAnd when you vote against it, can you tell me what is wrong? - Vadim Ovchinnikov
|
Fileclass, for example, like this:byte[] content = File.ReadAllBytes(<Путь к файлу>). TheFileclass has other methods . In general, it would not be bad to read about working with files in principle. Information - darkness. Here is just one example. - BlackWitcher