View Code 1 //读取服务器文件夹 2 void ExportExa(HttpContext context) 3 { 4 string[] aPath; 5 DirectoryInfo dInfo; 6 showS = new StringBuilder(); 7 if (Directory.Exists(context.Server.MapPath("temp"))) 8 { 9 aPath = Directory.GetDirectories(context.Server.MapPath("temp"));//获取文件夹的子文件夹 10 try 11 { 12 foreach (string itemPath in aPath)//循环Temp文件夹 13 { 14 dInfo = new DirectoryInfo(itemPath); 15 xName = dInfo.Name; 16 foreach (string item in Directory.GetDirectories(itemPath))//循环乡镇文件夹 17 { 18 dInfo = new DirectoryInfo(item); 19 showS.Append("\r\n"); 20 showS.Append(dInfo.Name + "---------------------------------------------------------------------------------\r\n"); 21 ProcessDirectory(context, item); 22 } 23 24 } 25 } 26 catch (Exception ex) 27 { 28 showS.Append("错误:" + ex + "\r\n"); 29 } 30 finally 31 { 32 //写入txt文件 33 using (FileStream txtFs = new FileStream(context.Server.MapPath(@"temp\" + xName + ".txt"), FileMode.Create)) 34 { 35 using (StreamWriter txtsw = new StreamWriter(txtFs, System.Text.Encoding.UTF8)) 36 { 37 txtsw.Flush(); 38 txtsw.BaseStream.Seek(0, SeekOrigin.Begin); 39 txtsw.Write(showS.ToString()); 40 txtsw.Flush(); 41 txtsw.Close(); 42 } 43 txtFs.Close(); 44 } 45 ResponseMang(context, "导入完成"); 46 //this.Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", ""); 47 } 48 } 49 }
....还有代码发布出错!!!!
最新评论