NPOI,导出Execl,压缩文件zip,发送Email

1private void SendEmail(string emailAddress, string companyName,string proxy, string officer, DataTable dt) 2 { 3 ChangeOfOwnerReport report = new ChangeOfOwnerReport(); 4 MemoryStream stream = report.ExportToExcel(companyName, proxy, officer, dt); 5 6 string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("{0}.xls", "Nomination Notice " + Guid.NewGuid().ToString())); 7 FileStream ss = new FileStream(fileName, FileMode.OpenOrCreate); 8 byte[] data = stream.GetBuffer(); 9 ss.Write(data, 0, data.Length); 10 ss.Flush(); 11 ss.Close(); 12 13 EmailTransaction email = new EmailTransaction(); 14 //create zip file 15 string zipFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("{0}.zip", "Nomination Notice " + Guid.NewGuid().ToString())); 16 17 List<string> srcList = new List<string>(); 18 srcList.Add(fileName); 19 20 ZipUtility.Zip(zipFileName, srcList, String.Empty); 21 FileInfo zipFile = new FileInfo(zipFileName); 22 FileStream fs = zipFile.OpenRead(); 23 byte[] zipByte = new byte[(int)zipFile.Length]; 24 fs.Read(zipByte, 0, (int)zipFile.Length); 25 26 email.EmTrAttachment = zipByte; 27 email.EmTrAttachmentName = "Nomination Notice Response.zip"; 28 29 fs.Close(); 30 fs.Dispose(); 31 System.IO.File.Delete(zipFileName); 32 System.IO.File.Delete(fileName); 33 34 email.EmTrSubject = "Nomination Notice Response"; 35 email.EmTrTo = emailAddress; 36 string content = "Greetings\r\nPlease find attached CofCT adjudication of change of offender, request submitted by you.\r\nRegards"; 37 content += "\r\nCity of Cape Town Traffic management"; 38 email.EmTrContent = content; 39 40 EmailManager emailManager = new EmailManager(); 41 emailManager.SendMail(email); 42 }

NPOI 导出:

1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.IO; 6using System.Data; 7 8using SIL.AARTO.BLL.EntLib; 9using NPOI.HSSF.UserModel; 10using NPOI.HPSF; 11using NPOI.POIFS.FileSystem; 12using NPOI.SS.UserModel; 13using NPOI.SS.Util; 14 15namespace SIL.AARTO.BLL.Report 16{ 17 public class ChangeOfOwnerReport 18 { 19 private HSSFWorkbook wb; 20 private ISheet sheet; 21 public ChangeOfOwnerReport() 22 { 23 wb = new HSSFWorkbook(); 24 } 25 26 public MemoryStream ExportToExcel(string companyName,string proxy,string officer, DataTable dt) 27 { 28 try 29 { 30 MemoryStream stream = new MemoryStream(); 31 32 sheet = wb.CreateSheet(); 33 wb.SetSheetName(0, "Proxy Nomination Notice"); 34 35 this.createHeading(companyName, proxy, officer); 36 this.createTitle(); 37 this.createDataRows(dt); 38 39 for (int i = 0; i < 5; i++) 40 { 41 sheet.AutoSizeColumn((short)i); 42 } 43 44 wb.Write(stream); 45 return stream; 46 } 47 catch (Exception e) 48 { 49 EntLibLogger.WriteErrorLog(e, LogCategory.Exception, "COO"); 50 throw e; 51 } 52 } 53 54 private void createHeading(string companyName, string proxy, string officer) 55 { 56 IFont font = wb.CreateFont(); 57 font.Boldweight = (short)FontBoldWeight.BOLD; 58 font.FontHeightInPoints = (short)20; 59 60 ICellStyle style = wb.CreateCellStyle(); 61 style.Alignment = HorizontalAlignment.LEFT; 62 style.VerticalAlignment = VerticalAlignment.CENTER; 63 64 sheet.CreateRow(0); 65 66 ICell cell = sheet.GetRow(0).CreateCell(0); 67 cell.CellStyle = style; 68 HSSFRichTextString rtf = new HSSFRichTextString("Submitted by " + companyName + " Proxy " + proxy); 69 rtf.ApplyFont(font); 70 cell.SetCellValue(rtf); 71 CellRangeAddress region = new CellRangeAddress(0, 0, 0, 4); 72 sheet.AddMergedRegion(region); 73 74 IFont font1 = wb.CreateFont(); 75 font1.Boldweight = (short)FontBoldWeight.BOLD; 76 77 sheet.CreateRow(1); 78 79 ICell cell1 = sheet.GetRow(1).CreateCell(0); 80 cell1.CellStyle = style; 81 HSSFRichTextString rtf1 = new HSSFRichTextString("Processed by Officer:" + officer); 82 rtf1.ApplyFont(font1); 83 cell1.SetCellValue(rtf1); 84 CellRangeAddress region1 = new CellRangeAddress(1, 1, 0, 3); 85 sheet.AddMergedRegion(region1); 86 87 ICell cell2 = sheet.GetRow(1).CreateCell(4); 88 cell2.CellStyle = style; 89 HSSFRichTextString rtf2 = new HSSFRichTextString(DateTime.Now.ToString("yyyy-MM-dd")); 90 rtf2.ApplyFont(font1); 91 cell2.SetCellValue(rtf2); 92 } 93 94 private void createTitle() 95 { 96 sheet.CreateRow(2); 97 IFont fontHeading = wb.CreateFont(); 98 fontHeading.Boldweight = (short)FontBoldWeight.BOLD; 99 ICellStyle styleHeading = wb.CreateCellStyle(); 100 styleHeading.Alignment = HorizontalAlignment.CENTER; 101 styleHeading.VerticalAlignment = VerticalAlignment.CENTER; 102 103 ICell cell1 = sheet.GetRow(2).CreateCell(0); 104 cell1.CellStyle = styleHeading; 105 HSSFRichTextString rtf1 = new HSSFRichTextString("Notice No"); 106 rtf1.ApplyFont(fontHeading); 107 cell1.SetCellValue(rtf1); 108 109 ICell cell2 = sheet.GetRow(2).CreateCell(1); 110 cell2.CellStyle = styleHeading; 111 HSSFRichTextString rtf2 = new HSSFRichTextString("Registration"); 112 rtf2.ApplyFont(fontHeading); 113 cell2.SetCellValue(rtf2); 114 115 ICell cell3 = sheet.GetRow(2).CreateCell(2); 116 cell3.CellStyle = styleHeading; 117 HSSFRichTextString rtf3 = new HSSFRichTextString("Offence Date"); 118 rtf3.ApplyFont(fontHeading); 119 cell3.SetCellValue(rtf3); 120 121 ICell cell4 = sheet.GetRow(2).CreateCell(3); 122 cell4.CellStyle = styleHeading; 123 HSSFRichTextString rtf4 = new HSSFRichTextString("Offender"); 124 rtf4.ApplyFont(fontHeading); 125 cell4.SetCellValue(rtf4); 126 127 ICell cell5 = sheet.GetRow(2).CreateCell(4); 128 cell5.CellStyle = styleHeading; 129 HSSFRichTextString rtf5 = new HSSFRichTextString("Status"); 130 rtf5.ApplyFont(fontHeading); 131 cell5.SetCellValue(rtf5); 132 } 133 134 private void createDataRows(DataTable dt) 135 { 136 for (int i = 0; i < dt.Rows.Count; i++) 137 { 138 sheet.CreateRow(3 + i); 139 140 ICell cell1 = sheet.GetRow(3 + i).CreateCell(0); 141 cell1.SetCellValue(dt.Rows[i]["Notice No"].ToString()); 142 143 ICell cell2 = sheet.GetRow(3 + i).CreateCell(1); 144 cell2.SetCellValue(dt.Rows[i]["Registration"].ToString()); 145 146 ICell cell3 = sheet.GetRow(3 + i).CreateCell(2); 147 cell3.SetCellValue(dt.Rows[i]["Offence Date"].ToString()); 148 149 ICell cell4 = sheet.GetRow(3 + i).CreateCell(3); 150 cell4.SetCellValue(dt.Rows[i]["Offender"].ToString()); 151 152 ICell cell5 = sheet.GetRow(3 + i).CreateCell(4); 153 cell5.SetCellValue(dt.Rows[i]["Status"].ToString()); 154 } 155 } 156 } 157}

发邮件:EmailManager.cs

1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Data; 6using System.Data.SqlClient; 7using System.Net.Mail; 8 9using SIL.ServiceQueueLibrary.DAL.Entities; 10using SIL.ServiceQueueLibrary.DAL.Services; 11using System.ComponentModel; 12using System.Net; 13using System.IO; 14using System.Net.Mime; 15//using SIL.ServiceLibrary.Email; 16 17namespace SIL.ServiceLibrary 18{ 19 20 public class EmailManager 21 { 22 private string _from = string.Empty; 23 private string _userName = string.Empty; 24 private string _smtp = string.Empty; 25 private string _password = string.Empty; 26 private bool _isAuthenticate = false; 27 private int _port = 0; 28 static object lockEmail = new object(); 29 30 //readonly Email.EmailServerInformation emailServer = new Email.EmailServerInformation(); 31 //readonly string _connStr = string.Empty; 32 33 public EmailManager() 34 { } 35 36 public EmailManager(string from, string smtp, string userName, string password, bool isAuthenticate, int? port) 37 { 38 //this._connStr = connStr; 39 //_from = System.Configuration.ConfigurationManager.AppSettings["AdminEmailAddress"]; 40 //_smtp = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"]; 41 //_userName = System.Configuration.ConfigurationManager.AppSettings["SmtpUserName"]; 42 //_password = System.Configuration.ConfigurationManager.AppSettings["SmtpPassword"]; 43 //_isAuthenticate = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsAuthenticate"]); 44 //_port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpPort"]); 45 46 this._from = from; 47 this._smtp = smtp; 48 49 if (isAuthenticate) 50 { 51 this._userName = userName; 52 this._password = password; 53 this._isAuthenticate = isAuthenticate; 54 } 55 if (port != null) 56 { 57 this._port = port.Value; 58 } 59 } 60 61 /// <summary> 62 /// Update sentToQueueDateTime field by FK(emtrID) 63 /// </summary> 64 /// <param name="emTrID"></param> 65 /// <param name="sentToQueueDate"></param> 66 /// <returns></returns> 67 68 //public List<EmailTransaction> GetEmailTransaction(int pageSize) 69 //{ 70 71 // SqlParameter[] para = new SqlParameter[]{ 72 // new SqlParameter("@PageSize",SqlDbType.Int) 73 // }; 74 // para[0].Value = pageSize; 75 76 // EmailTransaction email = null; 77 // List<EmailTransaction> returnList = new List<EmailTransaction>(); 78 79 // SqlConnection con = new SqlConnection(this._connStr); 80 // SqlCommand cmd = con.CreateCommand(); 81 // cmd.CommandText = "SILCustom_EmailTransaction_GetEmailTransaction"; 82 // cmd.CommandType = CommandType.StoredProcedure; 83 // cmd.Parameters.AddRange(para); 84 85 // try 86 // { 87 // if (con.State == ConnectionState.Closed) 88 // con.Open(); 89 90 // using (SqlDataReader reader = cmd.ExecuteReader()) 91 // { 92 // while (reader.Read()) 93 // { 94 // email = new EmailTransaction(); 95 // email.EmTrId = (decimal)reader["EmTrId"]; 96 97 // email.EmTrTo = reader["EmTrTo"].ToString(); 98 // email.EmTrCc = reader["EmTrCc"].ToString(); 99 // email.EmTrBcc = reader["EmTrBcc"].ToString(); 100 // //email.EmTrFrom = reader["EmTrFrom"].ToString(); 101 // email.EmTrSubject = reader["EmTrSubject"].ToString(); 102 // email.EmTrContent = reader["EmTrContent"].ToString(); 103 // email.EmTrSendDate = reader["EmTrSendDate"] is DBNull ? null : (DateTime?)reader["EmTrSendDate"]; 104 // email.EmTrRetryCount = reader["EmTrRetryCount"] is DBNull ? null : (byte?)reader["EmTrRetryCount"]; 105 // email.EmTrSendSuccess = reader["EmTrSendSuccess"] is DBNull ? null : (bool?)reader["EmTrSendSuccess"]; 106 // email.LastUser = reader["LastUser"].ToString(); 107 // //email.EmTrLoadedDate = Convert.ToDateTime(reader["EmTrLoadedDate"]); 108 // // email.SentToQueueDateTime = reader["SentToQueueDateTime"] is DBNull ? null : (DateTime?)reader["SentToQueueDateTime"]; 109 // //email.IsHtmlEmail = Convert.ToBoolean(reader["EmTrIsHtml"]); 110 111 // returnList.Add(email); 112 // } 113 // } 114 115 // return returnList; 116 // } 117 // catch 118 // { 119 // return null; 120 // } 121 // finally 122 // { 123 // if (con.State == ConnectionState.Open) 124 // con.Close(); 125 // } 126 //} 127 128 public void GetEmailToSend() 129 { 130 //<add key="SmtpServer" value="smtp.163.com"/> 131 //<add key="UserName" value="test@163.com"/> 132 //<add key="Password" value="000000"/> 133 //System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); 134 135 string sql = " EmTrSendDate IS NULL AND (EmTrSendSuccess IS NULL OR EmTrSendSuccess= 0) AND (EmTrRetryCount IS NULL OR EmTrRetryCount < 3 )"; 136 int totalCount = 0; 137 TList<EmailTransaction> emails = new EmailTransactionService().GetPaged(sql, "", 0, 0, out totalCount); 138 MailMessage message = null; 139 foreach (EmailTransaction email in emails) 140 { 141 message = new MailMessage(); 142 143 message.From = new MailAddress(_from.Trim()); 144 145 if (!String.IsNullOrEmpty(email.EmTrTo)) 146 { 147 foreach (string addr in email.EmTrTo.Trim().Split(';')) 148 { 149 if (!String.IsNullOrEmpty(addr)) 150 message.To.Add(new MailAddress(addr)); 151 } 152 } 153 if (!String.IsNullOrEmpty(email.EmTrCc)) 154 { 155 foreach (string addr in email.EmTrCc.Trim().Split(';')) 156 { 157 if (!String.IsNullOrEmpty(addr)) 158 message.CC.Add(new MailAddress(addr)); 159 } 160 } 161 162 message.Subject = email.EmTrSubject; 163 message.Body = email.EmTrContent; 164 message.Priority = MailPriority.High; 165 166 //msg.Subject = message.Subject; 167 message.SubjectEncoding = System.Text.Encoding.UTF8; 168 169 message.BodyEncoding = System.Text.Encoding.UTF8; 170 message.IsBodyHtml = false; 171 172 //add attachment 173 if (!String.IsNullOrEmpty(email.EmTrAttachmentName) 174 && email.EmTrAttachment != null 175 && email.EmTrAttachment.Count() > 0) 176 { 177 message.Attachments.Add(AddAttachment(email.EmTrAttachment, email.EmTrAttachmentName)); 178 } 179 180 SmtpClient client = new SmtpClient(_smtp); 181 //client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); 182 //client.UseDefaultCredentials = true; 183 if (_isAuthenticate) 184 { 185 client.Credentials = new System.Net.NetworkCredential(_userName, _password); 186 client.DeliveryMethod = SmtpDeliveryMethod.Network; 187 } 188 else 189 { 190 client.UseDefaultCredentials = true; 191 //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; 192 //client.Credentials = CredentialCache.DefaultNetworkCredentials; 193 } 194 //client.EnableSsl = true; 195 196 if (_port > 0) client.Port = _port; 197 object userState = email.EmTrId; 198 try 199 { 200 lock (lockEmail) 201 { 202 client.Send(message); 203 //client.SendAsync(message, userState); 204 //EmailInterface e = new EmailInterface(); 205 //e.MhtUnLockCode = System.Configuration.ConfigurationManager.AppSettings["MhtUnLockCode"]; ; 206 //e.EmailUnLockCode = System.Configuration.ConfigurationManager.AppSettings["MailUnLockCode"]; 207 //e.SmtpServer = emailServer.SmtpServer; 208 209 //e.SendMail(email,emailServer); 210 //client.Send(message); 211 212 EmailTransaction emailTran = new EmailTransactionService().GetByEmTrId(email.EmTrId); 213 if (emailTran != null) 214 { 215 emailTran.EmTrSendDate = DateTime.Now; 216 emailTran.EmTrSendSuccess = true; 217 new EmailTransactionService().Save(emailTran); 218 } 219 } 220 //while (mailSent == false) 221 //{ 222 223 //} 224 } 225 catch (System.Net.Mail.SmtpException ex) 226 { 227 throw ex; 228 } 229 230 } 231 232 } 233 234 235 /// <summary> 236 /// Test function 237 /// </summary> 238 /// <param name="from"></param> 239 /// <param name="mailTo"></param> 240 /// <param name="subject"></param> 241 /// <param name="body"></param> 242 /// <returns></returns> 243 public bool SendEmail(string from, string mailTo, string subject, string body) 244 { 245 bool r = false; 246 try 247 { 248 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); 249 250 msg.To.Add(mailTo); 251 252 msg.From = new MailAddress(from, from, System.Text.Encoding.UTF8); 253 msg.Subject = subject; 254 msg.SubjectEncoding = System.Text.Encoding.UTF8; 255 msg.Body = body; 256 msg.BodyEncoding = System.Text.Encoding.UTF8; 257 msg.IsBodyHtml = true; 258 msg.Priority = System.Net.Mail.MailPriority.High; 259 SmtpClient client = new SmtpClient(); 260 client.Credentials = new System.Net.NetworkCredential("jakezyz@163.com", "test"); 261 client.Port = 25; 262 client.Host = "smtp.163.com"; 263 client.EnableSsl = true; 264 object userState = msg; 265 client.Send(msg); 266 r = true; 267 } 268 catch (System.Net.Mail.SmtpException ex) 269 { 270 throw ex; 271 } 272 return r; 273 274 275 } 276 277 public void SendMail(EmailTransaction emailTran) 278 { 279 try 280 { 281 if (emailTran != null) 282 { 283 emailTran.EmTrRetryCount = 0; 284 emailTran.EmTrCreatedDate = DateTime.Now; 285 emailTran.EmTrSendDate = null; 286 emailTran.EmTrSendSuccess = false; 287 new EmailTransactionService().Save(emailTran); 288 } 289 } 290 catch (Exception ex) 291 { 292 throw ex; 293 } 294 } 295 296 public static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e) 297 { 298 // Get the unique identifier for this asynchronous operation. 299 decimal token = (decimal)e.UserState; 300 301 if (e.Cancelled || e.Error != null) 302 { } 303 else 304 { 305 EmailTransaction emailTran = new EmailTransactionService().GetByEmTrId(token); 306 if (emailTran != null) 307 { 308 emailTran.EmTrSendDate = DateTime.Now; 309 emailTran.EmTrSendSuccess = true; 310 new EmailTransactionService().Save(emailTran); 311 } 312 } 313 314 } 315 316 public Attachment AddAttachment(byte[] attachment, string fileName) 317 { 318 try 319 { 320 MemoryStream ms = new MemoryStream(attachment); 321 string extension = Path.GetExtension(fileName); 322 323 ContentType contentType = null; 324 325 if (!String.IsNullOrEmpty(extension)) 326 { 327 switch (extension.ToLower()) 328 { 329 case ".zip": 330 contentType = new ContentType("application/x-zip-compressed"); break; 331 case ".pdf": 332 contentType = new ContentType("application/pdf"); break; 333 case ".doc": 334 contentType = new ContentType("application/msword"); break; 335 case ".docx": 336 contentType = new ContentType("application/msword"); break; 337 case ".xls": 338 contentType = new ContentType("application/x-excel"); break; 339 case ".xlsx": 340 contentType = new ContentType("application/x-excel"); break; 341 case ".txt": 342 contentType = new ContentType("text/plain"); break; 343 case ".html": 344 contentType = new ContentType("text/html"); break; 345 case ".htm": 346 contentType = new ContentType("text/html"); break; 347 default: 348 contentType = new ContentType("application/x-zip-compressed"); break; 349 } 350 } 351 else 352 { 353 contentType = new ContentType("application/x-zip-compressed"); 354 } 355 Attachment atth = new Attachment(ms, contentType); 356 atth.Name = fileName; 357 atth.NameEncoding = Encoding.UTF8; 358 //atth.TransferEncoding = TransferEncoding.SevenBit; 359 360 return atth; 361 } 362 catch (Exception ex) 363 { 364 throw ex; 365 } 366 } 367 } 368}

zip 压缩:要添加ICSharpCode.SharpZipLib.dll

1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Threading.Tasks; 6using ICSharpCode.SharpZipLib.Zip; 7using ICSharpCode.SharpZipLib.Checksums; 8using System.IO; 9 10namespace MvcModelApp.Common 11{ 12 public class ZipUtility 13 { 14 public static int Zip(string zipFileName, List<string> srcFiles, string password) 15 { 16 ZipOutputStream zipStream = null; 17 FileStream streamWriter = null; 18 string fileName; 19 int count = 0; 20 21 try 22 { 23 if (srcFiles == null) return count; 24 //Use Crc32 25 Crc32 crc32 = new Crc32(); 26 27 //Create Zip File 28 zipStream = new ZipOutputStream(File.Create(zipFileName)); 29 30 //Specify Level 31 zipStream.SetLevel(Convert.ToInt32(9)); 32 33 //Specify Password 34 if (password != null && password.Trim().Length > 0) 35 { 36 zipStream.Password = password; 37 } 38 39 //Foreach File 40 foreach (string file in srcFiles) 41 { 42 //Read the file to stream 43 streamWriter = File.OpenRead(file); 44 byte[] buffer = new byte[streamWriter.Length]; 45 streamWriter.Read(buffer, 0, buffer.Length); 46 streamWriter.Close(); 47 48 //Specify ZipEntry 49 crc32.Reset(); 50 crc32.Update(buffer); 51 fileName = file.Substring(file.LastIndexOf('\\') + 1); 52 ZipEntry zipEntry = new ZipEntry(fileName); 53 zipEntry.DateTime = DateTime.Now; 54 zipEntry.Size = buffer.Length; 55 zipEntry.Crc = crc32.Value; 56 57 //Put file info into zip stream 58 zipStream.PutNextEntry(zipEntry); 59 60 //Put file data into zip stream 61 zipStream.Write(buffer, 0, buffer.Length); 62 63 count++; 64 } 65 } 66 catch (Exception ex) 67 { 68 throw ex; 69 } 70 finally 71 { 72 //Clear Resource 73 if (streamWriter != null) 74 { 75 streamWriter.Close(); 76 } 77 if (zipStream != null) 78 { 79 zipStream.Finish(); 80 zipStream.Close(); 81 } 82 } 83 84 return count; 85 } 86 87 public static List<string> Unzip(string destFolder, string srcZipFile, string password) 88 { 89 List<string> fileList = new List<string>(); 90 ZipInputStream zipStream = null; 91 ZipEntry zipEntry = null; 92 FileStream streamWriter = null; 93 int count = 0; 94 int bufferSize = 2048; 95 96 try 97 { 98 zipStream = new ZipInputStream(File.OpenRead(srcZipFile)); 99 zipStream.Password = password; 100 101 while ((zipEntry = zipStream.GetNextEntry()) != null) 102 { 103 string zipFileDirectory = Path.GetDirectoryName(zipEntry.Name); 104 string destFileDirectory = Path.Combine(destFolder, zipFileDirectory); 105 if (!Directory.Exists(destFileDirectory)) 106 { 107 Directory.CreateDirectory(destFileDirectory); 108 } 109 110 string fileName = Path.GetFileName(zipEntry.Name); 111 if (fileName.Length > 0) 112 { 113 string destFilePath = Path.Combine(destFileDirectory, fileName); 114 115 streamWriter = File.Create(destFilePath); 116 int size = bufferSize; 117 byte[] data = new byte[bufferSize]; 118 long extractCount = 0; 119 while (true) 120 { 121 size = zipStream.Read(data, 0, data.Length); 122 if (size > 0) 123 { 124 streamWriter.Write(data, 0, size); 125 } 126 else 127 { 128 break; 129 } 130 extractCount += size; 131 } 132 133 streamWriter.Flush(); 134 streamWriter.Close(); 135 fileList.Add(fileName); 136 count++; 137 138 } 139 } 140 } 141 catch (Exception ex) 142 { 143 throw ex; 144 } 145 finally 146 { 147 if (zipStream != null) 148 { 149 zipStream.Close(); 150 } 151 152 if (streamWriter != null) 153 { 154 streamWriter.Close(); 155 } 156 } 157 158 return fileList; 159 } 160 } 161}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )