-1

In c# How many way to open file? Which one is best? and how to open .exe file? Sorry for silly question but i am new in c#.

using (StreamReader srStreamReader = new StreamReader(sString))
      {
        while ((sline = srStreamReader.ReadLine()) != null)
         {
            Console.WriteLine(sline);
         }
     }

I am use this code for this but am not able. so please help

3 Answers3

0

By open file do you mean execute it or read line by line?

If execute then probably something like this is the answer:

    Process.Start("C:\\");
phoenix
  • 365
  • 1
  • 4
  • 15
0

If I understood the problem correctly

You can use like this

string path;
byte[] bufferArray = File.ReadAllBytes(path);
string base64EncodedString = Convert.ToBase64String(bufferArray );


bufferArray = Convert.FromBase64String(base64EncodedString );
File.WriteAllBytes(path, bufferArray );
Erdem Köşk
  • 190
  • 1
  • 10
  • - I have an easier solution, here: `using (var sw = new StreamReader(ofd.FileName, Encoding.GetEncoding("windows-1252"))) { var s = sw.ReadToEnd(); s = s.Replace('\x0', ' '); // replace NUL bytes with spaces richTextBox1.Text = s; }` – Momoro Nov 18 '19 at 19:41
0

From the code you've provided, it looks like you want to be able to view the source of an .exe. This can't be done without using a decompiler and knowing what the application was compiled with.

If you're trying to execute the .exe file, then take a look at the static method System.Diagnostics.Process.Start(filePath).

If you're trying to actually read the contents, you can use ILSpy or other similar software to decompile the application to view source. ILSpy has source available on GitHub, so you'll be able to use that to get the contents you want.

Nathangrad
  • 1,426
  • 10
  • 25