首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急关于读取压缩文件的有关问题

2011-12-27 
急,关于读取压缩文件的问题请教各位,我在读取压缩文件包中的一个文件时出错.这句读不出数据流:inputStream

急,关于读取压缩文件的问题
请教各位,我在读取压缩文件包中的一个文件时出错.
这句读不出数据流:   inputStream   =   zip.GetInputStream(entry);
代码如下:
  public   List <ReportInputResult>   SubmitReport(System.IO.Stream   stream,   DateTime   reportDuration,   Guid   reportOrganID,   int   adminorganType,   ReportPeriod   period)
                {
                        List <ReportInputResult>   resultList   =   new   List <ReportInputResult> ();

                        //从压缩包中读取报表编码

                        ZipFile   zip   =   new   ZipFile(stream);
                       
                        foreach   (ZipEntry   entry   in   zip)
                        {
                                if   (entry.IsFile   &&   (entry.Name.EndsWith( ".xls ")   ||   entry.Name.EndsWith( ".XLS ")))                                 {
                                        ReportInputResult   result   =   new   ReportInputResult();
                                        Stream   inputStream;
                                        ExcelDataSheetReader   excelSheet;
                                        string   reportType;
                                        try//判断上传的文件是否是EXCEL文件
                                        {
                                                inputStream   =   zip.GetInputStream(entry);
                                                excelSheet   =   new   ExcelDataSheetReader(inputStream,   0);
                                                excelSheet.SkipToRow(1);
                                                excelSheet.SkipToColumn(1);
                                                reportType   =   excelSheet.Read();


                                        }
                                        catch(Exception   ex)
                                        {
                                                result.ReportName   =   entry.Name;
                                                result.ErrorMessage   =   "上传失败:文件格式无法识别! "   +   ex.Message;
                                                result.IsSuccess   =   false;
                                                resultList.Add(result);
                                                continue;
                                        }
                                  }
                        }
                        return   resultList;
                }


我在调试时有以下信息:

“zip.GetInputStream(entry).ReadTimeout”引发了“System.InvalidOperationException”类型的异常

[解决办法]
System.IO.Stream str2;
System.IO.FileStream fs = new System.IO.FileStream( "c:\\123\\123.zip ", FileMode.Open);
ZipFile zip = new ZipFile(fs);
foreach (ZipEntry entry in zip)
{
str2 = zip.GetInputStream(entry);
}

fs.Close(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!可能因为你的流没有关闭
//我试了,如果不关闭流很有可能第二次打不开
[解决办法]
可以用:SharpZiplib
http://www.icsharpcode.net/OpenSource/SharpZipLib/

热点排行