开发者

Stream file name or converting stream to DataTable

I am getting S开发者_C百科ystem.IO.Stream object from an interface.

I want to get the path of file name from which stream is connect . As the stream will be to an excel file Or can I just read the stream and convert it into dataTable ?


You can not get the filename for all streams - it has to be a FileStream :

    if (strm is FileStream)
    {
       FileStream fs = (FileStream)strm;
       string name = fs.Name;
    }

And No, you cannot convert just any stream to a DataTable. It depends on what is inside the stream.


And if this is a memory stream and there is no file involved?

A Stream doesn't have source information, so you can't get this data (i.e. filename).

As for converting a Stream to a DataTable - you can load XML to a DataTable using the ReadXml method and using the constructor overload that takes a StreamingContext, but these wouldn't simply take an excel file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜