日期:2014-05-19  浏览次数:20362 次

CS 下载
请问用CS写下载怎么写
下载.FTP   .HTTP


------解决方案--------------------
(一).上传
1.
<INPUT id= "WebFile " style= "WIDTH: 490px; HEIGHT: 22px " type= "file " size= "62 " name= "WebFile " runat= "server ">
protected System.Web.UI.HtmlControls.HtmlInputFile WebFile;
文件上传参考代码:
/// <summary>
/// 文件上传
/// </summary>
/// <param name= "sender "> </param>
/// <param name= "e "> </param>
private void BtnUpload_Click(object sender, System.EventArgs e)
{
if(WebFile.PostedFile.FileName== " ")
{
Info.Text= "请先选择要上传的文件 ";
return;
}

try
{
char[] spliter = { '\\ '};
string [] FileName = WebFile.PostedFile.FileName.Split(spliter,10);

string FullPath = CurrentPath + @ "\ " + FileName[FileName.Length-1]; //生成完整文件名
WebFile.PostedFile.SaveAs(FullPath); //保存文件
LoadDir(CurrentPath); //重新载入当前目录
}
catch
{
Info.Text= "上传文件失败,请与管理员联系 ";
}
}

2.
http://www.gdcic.net/dotnetBank/ViewContent.aspx?artid=000000000186

(二).下载

1. C#:
/// <summary>
/// 文件下载
/// </summary>
/// <param name= "FullFileName "> </param>
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType= "application/octet-stream ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader( "Content-Length ",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}


2. vb.net
Public Sub WriteDLWindow(ByVal strFileName As String, ByVal page As System.Web.UI.Page)
Try
If File.Exists(page.MapPath(strFileName)) Then
Dim TargetFile As FileInfo = New FileInfo(page.MapPath(strFileName))
'清除缓冲区流中的所有内容输出.
page.Response.Clear()
'向输出流添加HTTP头 [指定下载/保存 对话框的文件名]
page.Response.AppendHeader( "Content-Disposition ", "attachment; filename= " + page.Server.UrlEncode(TargetFile.Name))

'繁体格式
'page.Response.AppendHeader( "Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8))

'向输出流添加HTTP头 [指定文件的长度,这样下载文件就会显示正确的进度
page.Response.AppendHeader( "Content-Length ", TargetFile.Length.ToString())
'表明输出的HTTP为流[stream],因此客户端只能下载.
page.Response.ContentType = "application/octet-stream "
'发送文件流到客户端.
page.Response.WriteFile(TargetFile.FullName)
'停止执行当前页
page.Response.End()
End If
Catch ex As Exception
Throw ex
End Try
End Sub

Set save file format:
Response.ContentType = "application/ms-excel ";