【问题标题】:Find out file extension from a System.IO.Stream object从 System.IO.Stream 对象中找出文件扩展名
【发布时间】:2011-08-08 14:37:05
【问题描述】:

我有一个方法,它返回从文件初始化的 System.IO.Stream 对象。我想断言流对象是为具有正确文件扩展名的文件创建的。

有什么办法可以做到吗?

谢谢

【问题讨论】:

    标签: asp.net file stream .net


    【解决方案1】:

    由于您的Stream 对象是从文件初始化的(希望是从文件名称),它应该是FileStream。因此,您可以使用其Name 属性来获取底层文件的名称:

    FileStream fileStream = yourStream as FileStream;
    if (fileStream != null) {
        string extensionWithDot = Path.GetExtension(fileStream.Name);
        // Now test the file extension.
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-06
      • 1970-01-01
      • 2012-05-13
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多