62,041
社区成员
发帖
与我相关
我的任务
分享
System.IO.StreamWriter sr;
fileName = Server.MapPath("..\\readbook\\download\\" + ds.Tables[0].Rows[0]["b_name"] + ".txt");
if (!File.Exists(fileName))
{
sr = File.AppendText(fileName);
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
sr.Write(ds.Tables[0].Rows[i]["b_name1"].ToString() + "<br/><br/>" + ds.Tables[0].Rows[i]["b_name2"].ToString() + "<br/><br/>" + Server.HtmlDecode(Encoding.Unicode.GetString((byte[])ds.Tables[0].Rows[i]["b_message"])) + "<br/><br/>");
}
sr.Flush();
sr.Close();
}
//压缩
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " 1.rar " + " " + @"C:\1\1.txt";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = @"C:\1";//获取或设置要启动的进程的初始目录。
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write("压缩成功");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
using System.IO;
using System.IO.Compression;
public static void fileCompress(string f_name)
{
string filename =HttpContext.Current.Server.MapPath(f_name);
FileStream infile = File.OpenRead(filename);
byte[] buffer = new byte[infile.Length];
infile.Read(buffer, 0, buffer.Length);
infile.Close();
FileStream outfile = File.Create(Path.ChangeExtension(filename, "zip"));
GZipStream gz = new GZipStream(outfile, CompressionMode.Compress);
gz.Write(buffer, 0, buffer.Length);
gz.Close();
}