如何从Asp.net 2.0中的服务器下载文件 [英] how to download a file from the server in Asp.net 2.0

查看:57
本文介绍了如何从Asp.net 2.0中的服务器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在做一个咨询网站,候选人可以在其中上传简历并存储在服务器的文件夹中.现在,当网站管理员进入时,他必须一次选择一个特殊的简历才能从保存在该文件夹中的文件夹中下载Godaddy接入了他的PC.我搜索了很多类似的活动.但是我不清楚它的含义.任何人都可以向我提出有关如何在我的网页中实现此下载部分的建议.

在此先感谢

Dhanya

Hello all,

I''m doing a consultancy site in which the candidates can upload their cv.& stored in a folder in the server.Now when the site admin enters he has to select a PARTICULAR CV at a time to download from the folder saved in the godaddy acct to his PC.I searched a lot of similar activities.But I couldn''t understand it clearly.Could any one give me a suggestion about how to implement this download portion in my webpage.

Thanks in Advance

Dhanya

推荐答案

通过以下链接.
文件下载 [
Go through the following link.
File Download[^]


如果您需要HTTP下载,可以使用我的HTTPDownloader应用程序作为示例.我在过去的答案中发布了完整的源代码:
如何从Internet下载文件 [ ^ ].

即使这是一个控制台应用程序,您也可以只下载足够简单的下载代码.实现了一项重要功能:如果文件的下载过程在中间中断,则可以继续下载部分下载的文件,然后再完成文件的下载.

现在,如果要下载FTP,代码将有所不同.

一种选择是使用WebRequestMethods.Ftp.DownloadFile: http://msdn.microsoft. com/en-us/library/system.net.webrequestmethods.ftp.downloadfile.aspx [ http://msdn.microsoft.com/en -us/library/system.net.ftpwebrequest.aspx [
If you need HTTP download, you can use my HTTPDownloader application for sample. I posted full source code in my past answer:
how to download a file from internet[^].

Even though this is a console application, you can take just the downloading code which is simple enough. One important feature is implemented: possibility to continues download of partially downloaded file, if the process was broken in the middle, before download of a file is complete.

Now, if you want FTP download, the code is different.

One option is using WebRequestMethods.Ftp.DownloadFile: http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.downloadfile.aspx[^].

Another option is using FtpWebRequest class: http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^].

—SA


尝试一下..
Try This One..
string filepath = Server.MapPath("-- File Path Here --");
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo myfile = new FileInfo(filepath);

// Checking if file exists
if (myfile.Exists)
{

// Clear the content of the response
Response.ClearContent();

// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);

// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());

// Set the ContentType
//    Response.ContentType = ReturnExtension(myfile.Extension.ToLower());

// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);

// End the response
Response.End();

}


如果您怀疑重播我..


If You Doubts Replay Me Back..


这篇关于如何从Asp.net 2.0中的服务器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆