上传解压包

a260881071 2009-05-11 11:30:48
上传一个解压包后自动解压到某个位置,然后根据解压包根目录下文件的个数向数据库中插入记录,比如说有三个文件就插三条记录。(根目录下都是.sw1或.sw2文件)



以前用那种多个文件上传的时候是通过上传文件的个数来确定插入数据库记录的条数。
...全文
238 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kele1006 2009-05-19
  • 打赏
  • 举报
回复
/// <summary>
/// 调用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();
}
guangyang475 2009-05-18
  • 打赏
  • 举报
回复
学习
skyaspnet 2009-05-15
  • 打赏
  • 举报
回复
学习
xuan.ye 2009-05-14
  • 打赏
  • 举报
回复
8楼 这个可以
a260881071 2009-05-11
  • 打赏
  • 举报
回复
我用的是 vs2003
「已注销」 2009-05-11
  • 打赏
  • 举报
回复
可以使用.Net 自带的解压缩类,但是好像不支持 WinRaR 压缩格式....
wuyq11 2009-05-11
  • 打赏
  • 举报
回复
通过SharpZipLib解压文件到文件夹,再遍历文件夹获取文件数
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();
}
}
绝代坏坏 2009-05-11
  • 打赏
  • 举报
回复
直接调用rar dll就可以
spring1_ 2009-05-11
  • 打赏
  • 举报
回复
不知道是不是你想要的:
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)
{}
spring1_ 2009-05-11
  • 打赏
  • 举报
回复
if(File1.PostedFile.FileName!=""&&File1.PostedFile.ContentLength>0)
{
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);
}
tulong403 2009-05-11
  • 打赏
  • 举报
回复
那就比较难做了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧