2011-08-08 57 views

回答

4

由於你Stream對象是從文件初始化(希望,從文件),它應該是一個FileStream。因此,您可以使用其Name屬性獲取基礎文件的名稱:

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