Reading a File Via Stream

W

william.oram

One function in this fabulous DLL (http://www.codeproject.com/KB/
office/excelxmllibrary.aspx) requests a file read in the form of the
Stream class...not StreamWriter or StreamReader or MemoryStream, just
Stream. Since Stream is abstract, this makes it hard. I've done my
best to bounce from Stream to MemoryStream to whatever else, but it
just isn't working out. Here's all I have so far, which isn't much.
Can someone fill in the blanks? Thanks!


public void GetData()
{
using (Stream stream = new MemoryStream())
using (FileStream file = new FileStream(stream))
{
// what goes here?
book = ExcelXmlWorkbook.Import(stream);
}
}
 
P

Peter Ritchie [C# MVP]

I'm not familiar with Excel XML Library, but you should be able to do
something like this:

using (FileStream fs = File.OpenRead(@"filename.ext"))
{
book = ExcelXmlWorkbook.Import(fs);
}
 
I

Ignacio Machin ( .NET/ C# MVP )

One function in this fabulous DLL (http://www.codeproject.com/KB/
office/excelxmllibrary.aspx) requests a file read in the form of the
Stream class...not StreamWriter or StreamReader or MemoryStream, just
Stream. Since Stream is abstract, this makes it hard.

Why?
Stream s = new FileStream( ...);
 
W

william.oram

Why?
Stream s = new FileStream( ...);

Hrm, I swear I tried that. Actually, I probably did, but your comment
led me on the right track:

public void GetData()
{
using (Stream iStream = File.OpenRead(filePath))
{
book = ExcelXmlWorkbook.Import(iStream);
worksheet = book[0];
}
}

Thanks for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top