打开对话框保存为txt
1 #region 2 this.dDownTable = (DataTable)(this.dg1.DataContext); 3 if (this.dDownTable.Rows.Count > 0) 4 { 5 string fName = string.Empty; 6 System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 7 saveFileDialog.Filter = "TXT FIlE(*.txt)|*.txt"; 8 saveFileDialog.FilterIndex = 2; 9 saveFileDialog.RestoreDirectory = true; 10 saveFileDialog.FileName = "SolarProtonEvents"; 11 if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) 12 { 13 fName = saveFileDialog.FileName; 14 15 //写入文件 16 StringBuilder sb = new StringBuilder(); 17 // sb.Append("SPE Start".PadLeft(13)+ " Proton Flux Max Time".PadRight(19)+" Proton Flux Max".PadRight(23)+" Associated CME".PadRight(25)+" Flare Max Time".PadRight(22)+" Flare Max".PadRight(19)+"Location".PadRight(14)+" Region".PadRight(10)+" "); 18 19 20 sb.Append(" # Prepared by Space Environment Prediction Center "+ 21 "# Please send comments and suggestions to sepcwebmaster@sepc.ac.cn "+ 22 "# "+"# SPE Start: Column 1-17, time when SPE started (UT), and the format is "YYYY-MM-DD HH:MM". "+ 23 "# Proton Flux Max Time: Column 26-42, time when the proton flux reached the peak during the SPE, and the format is "YYYY-MM-DD HH:MM". "+ 24 "# Proton Flux Max: Column 50-54, peak value of the proton flux during the SPE. "+ 25 "# Associated CME: Column 66-77, associated CME that may be possible cause of the SPE. "+ 26 "# Flare Max Time: Column 82-98, Time when the X-ray flux reached the peak, and the format is "YYYY-MM-DD HH:MM". "+ 27 "# Flare Max: Column 106-110, Flare class. "+ 28 "# Location: Column 122-132, region location of the solar disk. "+ 29 "# Region #: Column 138-142, region number by SWPC. " 30 ); 31 foreach (DataRow dr in dDownTable.Rows) 32 { 33 sb.Append(dr["Start"].ToString().PadRight(25) ); 34 sb.Append(dr["Max"].ToString().PadRight(24) ); 35 sb.Append(dr["Proton"].ToString().PadRight(16) ); 36 sb.Append(dr["CME"].ToString().PadRight(16) ); 37 sb.Append(dr["Flare"].ToString().PadRight(24) ); 38 sb.Append(dr["Xray"].ToString().PadRight(16) ); 39 sb.Append(dr["Location"].ToString().PadRight(16) ); 40 sb.Append(dr["Region"].ToString() + " "); 41 //sb.Append(dr["imgkp1"].ToString() + " "); 42 //sb.Append(dr["imgkp2"].ToString() + " "); 43 // sb.Append(dr["time"].ToString() + " "); 44 // sb.Append(dr["xray1"].ToString() + " "); 45 // sb.Append(dr["xray2"].ToString() + " "); 46 // sb.Append(dr["Proton1"].ToString() + " "); 47 sb.Append(" "); 48 } 49 Util.FileOperate.WriteFile(fName, sb.ToString()); 50 } 51 } 52 #endregion
1 #region 写文件 2 /// <summary> 3 /// 写文件 4 /// </summary> 5 /// <param name="Path">文件路径</param> 6 /// <param name="Strings">文件内容</param> 7 public static void WriteFile(string FileFullPath, string Strings) 8 { 9 if (!System.IO.File.Exists(FileFullPath)) 10 { 11 System.IO.FileStream fs = System.IO.File.Create(FileFullPath); 12 fs.Close(); 13 } 14 System.IO.StreamWriter sw = new System.IO.StreamWriter(FileFullPath, false, System.Text.Encoding.GetEncoding("gb2312")); 15 sw.Write(Strings); 16 sw.Flush(); 17 sw.Close(); 18 sw.Dispose(); 19 } 20 #endregion