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

解决方案 »

  1.   

    (一).上传
    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";
      

  2.   

    楼主:
    你要的是服务端代码还是客户端代码??ChengKing((.net: http://blog.csdn.net/ChengKing )) :
    我服了你了,都不知道人家要的是哪端的代码,就贴上这么一大段。呵呵…………
      

  3.   

    lizheng__114(浪淘沙) ( ) 信誉:100    Blog   加为好友  2007-05-12 15:12:24  得分: 0     怎么下载客户端也需要什么代码的吗?
    ------------------------------------------------------
    怎么不需要呢?下载软件也算是客户端吧?!
      

  4.   

    要从服务端下载
    下载FTP和HTTP两种