需要为一个网站弄个ftp,有上传和下载功能,该如何写。高手给个思路
解决方案 »
- 急!关于超链接的一点问题
- ScriptManager的问题,在线等
- DataNavigateUrlFormatString 怎么写才能在新建的标签页中打开
- 我的.net程序运行不起来---在线等
- 在鼠标选择左右插入符号!!
- 丽丽的问题--新建asp.net工程里面的文件都什么意思啊?????
- 菜鸟级问题,asp.net数据存储和修改(请不要笑)
- 怎么asp:ScriptManager 在vs 2005中找不到呢
- 请问怎样能从主页面aspx中获得用户控件ascx的属性值?我好急,帮帮忙?
- 请教-微软全球技术中心 一个问题: 在ASP.NET中如何解决编码转换问题??急需!!!!
- asp调用asp.net的webservice返回403
- VS2005 Ajax web.config requirePermission
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") + "");//传递参数到下载压缩包的页面,下载完成后把生成的压缩包删除掉
}这里的创建压缩文件夹采用了ICSharpCode.SharpZipLib.Zip,其下载地址是:
http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx这里调用了 fastZip.CreateZip(zipfilename, filefolder, true, "");来创建压缩包,注意这里的第一个参数要写存储的文件的全路径,否则不能生成压缩文件 batch.CreatePackageByCompanyFileDomain(lists);
这里是根据选择的文件创建临时文件包 /// <summary>
/// 根据文件列表创建下载文件夹,并在文件夹里放置所有文件及其附件
/// </summary>
/// <param name="companyfiles"></param>
public void CreatePackageByCompanyFileDomain(List<CompanyFileDomain> companyfiles)
{
if (companyfiles.Count > 0)
{
foreach (CompanyFileDomain fileEntity in companyfiles)
{
CreatePackageByCompanyFileDomain(fileEntity);
}
}
}
/// <summary>
/// 根据文件ID创建单个文件夹,并在其中放置文件及其附件
/// </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);//重命名的实现
}
}
更多详细内容请查看:http://www.111cn.net/net/35/33288.htm