-3

I'm a little new to C# but I had started working on this project for a company and I'm a little stuck as to how to even prepare this code.

A little background, the company has been trying to read an excel file from the local machine and display it as a DataTable in C# so that it may correlate with the fields/values inside the excel file. Since that method is still kind of "hard-coded" they want something more "automated" so they tasked me with reading from the .exe file in the Debug folder of my solution and attempt to display it inside the C# code as a DataTable (or similar) so that I may read all contents of it and update our website with that information. I would also like to know if it's possible, as I'm not sure if it is or not, so by any means correct me if I'm wrong.

I have looked around google for similar help topics but it seems none match my case exactly.

I do not need to be spoon-fed anything but a little helper code or a step in the right direction will be greatly useful for me and appreciated.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Lazaro R.
  • 39
  • 8
  • 3
    `it seems none match my case exactly` Are you under the impression that software develop is a matter of google and pasting code? This is too broad and vague – Ňɏssa Pøngjǣrdenlarp Feb 27 '18 at 16:57
  • > Are you under the impression that software develop is a matter of google and pasting code? Well actually, now that you mention it... – James Parsons Feb 27 '18 at 17:04
  • 2
    CS stand for Computer Science not Copy Something – Ňɏssa Pøngjǣrdenlarp Feb 27 '18 at 17:05
  • 1
    You want to do what now? It even sounds funny that "the company has been trying to read an Excel file and display it as a DataTable". And now it gets more interesting when they want to transfer the data from a compiled executable file to a website... You need to rephrase your question so that it is more clear and make it more specific. – bitoolean Feb 27 '18 at 17:08
  • Why is the Excel file an EXE? If you kept it in XLS or XLSX format you could just connect to it [hint] via System.Data – Mad Myche Feb 27 '18 at 17:32

1 Answers1

-1

You can load the file into a byte[] and then manipulate it any way you like, including saving it to the database.

private byte[] ReadFileBytes(FileInfo file)
{
    byte[] buffer = new byte[file.Length];

    using (FileStream stream = file.OpenRead())
    {
        stream.Read(buffer, 0, buffer.Length);
    }

    return buffer;
}
Zoran Horvat
  • 10,924
  • 3
  • 31
  • 43
  • @MadMyche This is the step in the right direction, and a necessary one if OP was ever to store it into the database. Should the question be updated with more details, I would add more to the answer. Especially *nothing to do with putting into a DB* is entirely wrong, because byte buffer is very suitable to be saved into the DB, obviously, unlike the file, which is not. – Zoran Horvat Feb 27 '18 at 22:09
  • @MadMyche On a related note, you have complained about the answer which OP has accepted. – Zoran Horvat Feb 27 '18 at 23:13
  • I had misworded my original comment... The OP wrote a lousy question, and did not mention database, just displaying via data-table. So while your answer may be technically correct; it may not have any thing to do with what is actually needed. – Mad Myche Feb 28 '18 at 16:48