if (FileUpload1.HasFile)
{
string FileName1 = FileUpload1.FileName;
//Web.config中获得上传路径
FilePath = ConfigurationManager.AppSettings["stringPath"].ToString();
FilePath += FileUpload1.FileName;
//如果指定的目录中有同名的文件
if (File.Exists(FilePath))
{
MC.Common.MessageBox.Show(Page, "上传失败!已经存在该文件的同名文件");
return;
}
FileUpload1.PostedFile.SaveAs(FilePath);
DateTime dt = DateTime.Now;
//上传人名称
string PersonName;
//获得登录者的姓名
PersonName = Acurity.AcurityCheck.ReadXML(1);
}
//读取XML文件信息
public static string ReadXML(int userIndex)
{
using (XmlTextReader Reader = new XmlTextReader(FPath + "//config.xml"))
{
List<string> UserList = new List<string>();
while (Reader.Read())
{
if (Reader.NodeType == XmlNodeType.Text)
UserList.Add(Reader.Value);
}
if (UserList.Count == 0)
{
return null;
}
else
{
if (UserList.Count < userIndex)
return "";
else
return UserList[userIndex];
}
}
}
public void RARsave(string patch, string rarPatch, string rarName)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = "WinRar";//the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
protected void MoreDownLoad_ServerClick(object sender, EventArgs e)
{
if (Request.Form["hh"]==null)
{
MC.Common.MessageBox.Show(Page,"请选择要下载的文件");
return;
}
try
{
string []houPath = Request.Form["hh"].Split(',');
System.Random random = new Random();
string FileFolder = DateTime.Now.ToString("HHMMssffff") +random.Next(100000000);
//合并路径
string TempFileFolder = Path.Combine(FilePath, FileFolder);
//创建路径和文件夹
Directory.CreateDirectory(TempFileFolder);
for (int i = 0; i < houPath.Length;i++ )
{
//获得文件的扩展名
//string extensionName= houPath[i].Substring(houPath[i].ToString().LastIndexOf('.'));
string Name12 = Path.GetFileName(houPath[i]);
File.Copy(houPath[i], TempFileFolder + @"/" + i + "-" + Name12);
}
//产生RAR文件,及文件输出
RARsave(TempFileFolder, "E://mydocument//", FileFolder + ".rar");
FileDownload( @"E:/" + FileFolder + ".rar");
}
catch(Exception rc)
{
MC.Common.MessageBox.Show(Page, "下载失败!" );
}
}
public void RARsave(string patch, string rarPatch, string rarName)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = "WinRar";//the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
public void FileDownload(string strFullName)
{
FileInfo DownloadFile = new FileInfo(strFullName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);//DownloadFile.FullName保存文件名
Response.Flush();
//Directory.Delete(strFullName);
//Response.End();
}