[
  {
    "Id": "699504",
    "ThreadId": "279803",
    "Html": "\r\n<p>I have zip file from which i am getting some record line by line in a text file</p>\r\n<pre lang=\"x-c#\"><div style=\"color:black; background-color:white\"><pre><span style=\"color:blue\">public</span> <span style=\"color:blue\">static</span> IEnumerable&lt;PDR&gt; GetPDRRecordList(<span style=\"color:blue\">string</span> fileName)\r\n{\t\t\t\r\n\tZipFile zipFile = <span style=\"color:blue\">new</span> ZipFile(fileName);\r\n            <span style=\"color:blue\">foreach</span> (ZipEntry ze <span style=\"color:blue\">in</span> zipFile.Where(ze =&gt; ze.FileName.ToLower().EndsWith(<span style=\"color:#a31515\">&quot;.pdr&quot;</span>)).AsParallel())\r\n            {\r\n                <span style=\"color:blue\">using</span> (BufferedStream buffer = <span style=\"color:blue\">new</span> BufferedStream(ze.OpenReader()))\r\n                {\r\n                    <span style=\"color:blue\">using</span> (StreamReader reader = <span style=\"color:blue\">new</span> StreamReader((buffer), Encoding.ASCII))\r\n                    {\r\n                        PDR obj = <span style=\"color:blue\">null</span>;\r\n                        <span style=\"color:blue\">string</span> line = <span style=\"color:blue\">string</span>.Empty;\r\n                        <span style=\"color:blue\">int</span> recordID = 0;\r\n                        <span style=\"color:blue\">while</span> ((line = reader.ReadLine()) != <span style=\"color:blue\">null</span>)\r\n                        {\r\n                            <span style=\"color:blue\">if</span> (line.Trim().Length &gt; 0)\r\n                            {\r\n                                recordID&#43;&#43;;\r\n                                obj = <span style=\"color:blue\">new</span> PDR();                               \r\n                                obj.RecordRowNumber = recordID;\r\n                                obj.JobID = line.Substring(0, 8).Trim().Length == 0 ? String.Empty : line.Substring(0, 8).ToLower();<span style=\"color:green\">//casesensitivecheck</span>\r\n                                obj.CQTDatabaseID = line.Substring(8, 8).Trim().Length == 0 ? String.Empty : line.Substring(8, 8);\r\n                                obj.PackageID = line.Substring(16, 6).Trim().Length == 0 ? String.Empty : line.Substring(16, 6).ToLower();<span style=\"color:green\">//casesensitivecheck</span>\r\n                                obj.PieceID = line.Substring(22, 22).Trim().Length == 0 ? String.Empty : line.Substring(22, 22).ToLower();<span style=\"color:green\">//casesensitivecheck                               </span>\r\n                                line = <span style=\"color:blue\">null</span>;\r\n                                <span style=\"color:blue\">yield</span> <span style=\"color:blue\">return</span> obj;\r\n                            }\r\n                        }\r\n                        reader.Close();\r\n                        reader.Dispose();\r\n                    }\r\n                    buffer.Close();\r\n                    buffer.Dispose();\r\n                }\r\n            }\r\n            zipFile.Dispose();\r\n            zipFile = <span style=\"color:blue\">null</span>;\r\n}\r\n</pre>\r\n</div>\r\n<br></pre>\r\n<p>As the File size can be from 10 Kb to 800MB can any body suggest me better way loop through each reacords</p>\r\n",
    "PostedDate": "2011-11-17T03:46:15.683-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "699944",
    "ThreadId": "279803",
    "Html": "<div style=\"width: 800px;\">\r\n<p>#1.&nbsp; you do not need to call buffer.Close() or buffer.Dispose() when buffer is declared in a using clause.&nbsp; Likewise for your reader object.</p>\r\n<p>#2. you should always employ a using clause for the ZipFile object.&nbsp; Your call to .Dispose() is not sufficient.&nbsp; Read the documentation on IDisposable for an explanation of why.&nbsp; Or just trust me. Follow the examples, and employ a using clause.</p>\r\n<p>#3. What problem are you trying to solve?&nbsp; You are asking for \"a better way\", and it's not clear how you are judging \"better\".&nbsp;If you need to loop through a large file, I don't know of \"a better way\" than to just loop through it. If there are 10,000 records, you will need to search all 10,000.&nbsp; But, this isn't really a DotNetZip question.</p>\r\n<p>&nbsp;</p>\r\n</div>",
    "PostedDate": "2011-11-17T17:54:54.863-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]