For the ExcelPackage constructor you need a FileInfo object. I rather use some kind of stream object(f.i. MemoryStream), because I don't need to save the file to the server itself, but expose it as a FileStream anyway to the user. I don't want to make files which I have to delete lateron from servers which are only there for generating purposes and never used again. Apart from that, otherwise I need also the necessary rights for the application/user on the directory/file on the server.
So my question is then: How can I convert a stream object to a FileInfo object.
Deserializing (converting byte array into Object)
C# FileInfo PropertiesIt is used to get or set the creation time of the current file or directory. It is used to get an instance of the parent directory. It is used to get a string representing the directory's full path. It is used to get a value indicating whether a file exists.
FileInfo Class (System.IO)Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.
Yes you can
var excelPackage = new ExcelPackage();
excelPackage.Load(fileStream);
You can't convert the Stream
as such to a FileInfo
; they represent entirely different things. A Stream
contains data thay may or may not represent a file on disk. A FileInfo
on the other hand contains metadata about a file, that may or may not exist.
What you can do is to write the contents of the Stream
to a file on disk, create a FileInfo
pointing at that file and pass that FileInfo
to the constructor.
A FileInfo
class is a simple wrapper around a path to a file on disk.
It is not possible to have a FileInfo
wrap a memory stream.
However, you can download the source code and add a constructor that takes a Stream
. (The file path is only used in the WriteDebugFile
method)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With