上传一个解压包后自动解压到某个位置,然后根据解压包根目录下文件的个数向数据库中插入记录,比如说有三个文件就插三条记录。(根目录下都是.sw1或.sw2文件)以前用那种多个文件上传的时候是通过上传文件的个数来确定插入数据库记录的条数。
解决方案 »
- IE6实现水平翻转图片!IE6 6 6 6 6 6
- .net mvc3 UpdateModel关于 未能更新类型“”的模型
- asp.net 怎么浏览器设置状态栏文本
- 哪位兄弟有ReSharper2.0-VS2003的汉化补丁~~~跪求~~~~
- 很郁闷的问题...
- 急问用VS.NET2002打开已经有虚拟目录对应的项目或者新建项目都出错的问题
- .net 开发wap网站需要什么技术?需要注意什么?
- 如何返回弹出窗口的值到父窗口中的用户控件中的文本框中?
- mvc 的身份验证问题
- asp.net出错以后就把所有的内容全部显示在页面上,这样是不是安全不够高?
- 如何实现动态新增gridview模板列。并把一个checkboxlist控件包含在这个模板列中。然后添加到gridview 中
- 如何将aspx映射成html ????谢谢~~~
{
if(("application/x-zip-compressed||application/octet-stream||application/x-gzip-compressed").IndexOf(File1.PostedFile.ContentType.Trim())<0)
{
Response.Write("<script> alert('您上传的软件必须为压缩文件!!!');</script>");
return;
}if(File1.PostedFile.ContentLength>200*1024*1024)
{
Response.Write("<script> alert('您上传的软件太大!!!');</script>");
return;
}
name1=System.Guid.NewGuid().ToString();
aa=File1.PostedFile.FileName;
aa=aa.Substring(aa.LastIndexOf('\\')+1);
string ext=System.IO.Path.GetExtension(File1.PostedFile.FileName).ToLower().Trim();
name1=name1+ext;
string bb=System.Configuration.ConfigurationSettings.AppSettings["UpLoadRoot"].ToString();
File1.PostedFile.SaveAs(bb+name1);
}
private string up_load(HtmlInputFile f)
{
string name=null; if(f.Value.Trim().Length>0)
{
string filename=System.IO.Path.GetFileName(f.PostedFile.FileName);
filename=filename.Replace(" ","-");
string path=System.Configuration.ConfigurationSettings.AppSettings["UpLoadRoot"].ToString(); try
{
f.PostedFile.SaveAs(path+filename);
name=filename;
}
catch
{
name=null;
this.Response.Write("<script>alert('上传文件失敗');</script>");
}
}
return name;
} private bool check_file(HtmlInputFile f)
{
bool b=false; string filename=System.IO.Path.GetFileName(f.PostedFile.FileName);
string path=System.Configuration.ConfigurationSettings.AppSettings["UpLoadRoot"].ToString();
if(File.Exists(path+filename))
{
b=true;
} return b;
}
private void Button1_Click(object sender, System.EventArgs e)
{
string filename=null;
if(File1.Value.Trim().Length>0)
{
if(check_file(File1))
{
this.Response.Write("<script>alert('文件名重覆,请修改文件名!')</script>");
return;
} filename=up_load(File1);
}...(File2,File3)
if(filename!=null)
{}
string []FileProperties=new string[2];
FileProperties[0]=strPath; //待解压的文件
FileProperties[1]=strPath+@"\"; //解压后放置的目标目录
UnZip(FileProperties);public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry = s.GetNextEntry();
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(args[1]+theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
}
/// 调用RAR进程进行解压缩
/// </summary>
/// rar <命令> -<开关 1> -<开关 N> "<压缩文件>" "<解压路径>"
/// x 用绝对路径解压缩文件
/// o+ 覆盖已存在文件
/// r 递归子目录
public void UnRAR(string rarDir, string rarName, string unRarDir){
Process process = new Process();
process.StartInfo.FileName = "winrar.exe";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.Arguments = "x -o+ -r \"" + rarName + "\" \"" + unRarDir + "\"";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.WorkingDirectory = rarDir;
process.Start();
process.WaitForExit();
process.Close();
}