asp.net file bulk upload download code and detailed instructions

Source: Internet
Author: User
Tags foreach urlencode zip

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
}
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.