1
votes

Right, so i have this code:

 Byte[] bin = p.GetAsByteArray();
 File.WriteAllBytes(@"C:\Report.xlsx", bin);

Now p is an ExcelPackage object, which is a class to manipulate xlsx files.

though p has data the following command just doesn't create the file and no errors occur.

I Believe it has something to do with the fact that i'm running this on windows 7, however i'm only debugging via VS.

I'm using .Net 4.5, Anyone knows what can be the issue?

1
I very much doubt that File.WriteAllBytes is silently failing. Is it even getting to that line? What has your debugging shown you? If it's a problem with the IO, then the source of the data is irrelevant, and you should be able to see the same thing in a short but complete console app which just writes a few random bytes to the same file.Jon Skeet
Well it is reaching that line, and if i try to write to console line before the WriteAllBytes and line after i see nothing in between.eric.itzhak
Win10 with the same problem. I tried suggestion to try another location and it worked. WriteAllBytes did silently fail for me while trying to write to my current directory, which was not C:\Dan Loughney

1 Answers

2
votes

You don't show enough code to pinpoint the problem exactly... very likely it is one of the following:

  • security

    in newer windows versions (like 7) you are not allowed to store files etc. directly on C:\ anymore.

  • p and/or bin is not in a state that allows saving.

EDIT - as per comment:

you can use any of ApplicationData / CommonApplicationData / LocalApplicationData from Environment.SpecialFolder in a call to Environment.GetFolderPath ()...

MSDN reference: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx