ASP tutorial. net file bulk upload download code and detailed description
private void Downloadcompressfile ()
{
Create File Package
list<companyfiledomain> lists = new list<companyfiledomain> ();
if (DeluxeGridFiles.SelectedKeys.Count > 0)
{
for (int i = 0; i < DeluxeGridFiles.SelectedKeys.Count; i++)
{
Companyfiledomain companyfile = CompanyFileAdapter.Instance.Load (Deluxegridfiles.selectedkeys[i]);
Lists. ADD (Companyfile);
}
}
batchfiles batch = new Batchfiles (DeluxeIdentity.CurrentUser.LogOnName);
if (lists!= null)
{
Batch. Createpackagebycompanyfiledomain (lists);
}
Compress package
String filepath =companyfileconfig.instance.filesavepath + "\" + DeluxeIdentity.CurrentUser.LogOnName;
String Filefolder=filepath + "\";
String Zipfilename =filepath + ". zip";
if (directory.exists (Filefolder))
{
Fastzip fastzip = new Fastzip ();
Zip filename is full file name
Fastzip.createzip (Zipfilename, Filefolder, True, "");
}
FileInfo ZipFile = new FileInfo (zipfilename);
if (ZipFile. Exists && directory.exists (Filefolder))
{
DirectoryInfo di = new DirectoryInfo (Filefolder);
Di. Delete (TRUE);
Directory.delete (Filefolder);
}
Download zip file
Response.Redirect ("Batchdown.aspx?") Fullfilepath= "+ httputility.urlencode (zipfilename) +" &filename= "+ httputility.urlencode ( DeluxeIdentity.CurrentUser.LogOnName + ". zip") + ""),//pass parameters to download the compressed package of the page, download the resulting compressed package deleted
}
The Create compressed folder here uses ICSharpCode.SharpZipLib.Zip, and its download address is:
Http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
Here we call Fastzip.createzip (Zipfilename, Filefolder, True, ""); to create a compressed package, note that the first parameter here is to write the full path of the stored file, or you cannot generate a compressed file
Batch. Createpackagebycompanyfiledomain (lists);
This is to create a temporary package based on the selected file
<summary>
Create a download folder from the file list and place all files and their attachments in the folder
</summary>
<param name= "Companyfiles" ></param>
public void Createpackagebycompanyfiledomain (list<companyfiledomain> companyfiles)
{
if (companyfiles. Count > 0)
{
foreach (Companyfiledomain fileentity in Companyfiles)
{
Createpackagebycompanyfiledomain (fileentity);
}
}
}
<summary>
Create a single folder based on the file ID and place the file and its attachments in it
</summary>
<param name= "ResourceID" ></param>
public void Createpackagebycompanyfiledomain (Companyfiledomain companyfile)
{
if (companyfile!= null)
{
if (! Directory.Exists (Downloadpath))
{
Directory.CreateDirectory (Downloadpath);
}
String sourcefilenamewithoutextend = Companyfile. Filename.substring (0,companyfile. Filename.length-companyfile.extendfilename.length);
String Sourcefilefullpath = Rootfilepath + companyfile. RelativePath + "\" + companyfile.id + companyfile. Extendfilename;
String desfilefolder = Downloadpath + sourcefilenamewithoutextend;
String Desfileattchfolder = String. Empty;
if (directory.exists (Desfilefolder))
{
Desfilefolder = Renamefolder (Desfilefolder);
}
Desfileattchfolder = Desfilefolder + "http://www.cnblogs.com/yungboy/admin/file://attchments//";
Directory.CreateDirectory (Desfilefolder);
FileInfo newFile = new FileInfo (Sourcefilefullpath);
Newfile.copyto (Desfilefolder + "\" + Companyfile.id + companyfile.) Extendfilename);
FileInfo tempfile = new FileInfo (Desfilefolder + "\" + Companyfile.id + companyfile.) Extendfilename);
Tempfile.moveto (Path.Combine, Desfilefolder, Companyfile. FileName));
Have attchement
Materiallist materials = MaterialAdapter.Instance.LoadMaterialsByResourceID (companyfile.id);
if (materials. Count > 0)
{
Directory.CreateDirectory (Desfileattchfolder);
foreach (Material ma in materials)
{
String sourceattchfullpath = Rootattchpath.remove (rootattchpath.length-1, 1);
Sourceattchfullpath + = Ma. RelativeFilePath;
FileInfo attfile = new FileInfo (Sourceattchfullpath);
Attfile.copyto (Desfileattchfolder + ma.id + attfile.extension);
FileInfo Tempatt = new FileInfo (desfileattchfolder + ma.id + attfile.extension);
Tempatt.moveto (Desfileattchfolder + ma. Originalname);//Renaming implementation
}
}
}
}