谁有,c#写的 上传 下载文件 的原代码,急用,谢谢!在线等待

解决方案 »

  1.   

    //下载文件方法
    private void filedownload(string fullfilename)
    {
    FileInfo downloadfile = new FileInfo(fullfilename);
    Response.Clear();
    Response.ClearHeaders();
    Response.Buffer=false;
    Response.ContentType="application/octe-stream";
    Response.AppendHeader("呵呵","文件名="+HttpUtility.UrlDecode(downloadfile.FullName,System.Text.Encoding.ASCII));
    Response.AppendHeader("文件长度",downloadfile.Length.ToString());
    Response.WriteFile(downloadfile.FullName);
    Response.Flush();
    Response.End();
    }
    filedownload(listfile.SelectedItem.Text);  //下载文件
      

  2.   

    上传文件private void Button3_Click(object sender, System.EventArgs e)
    {
    if(textfileup.PostedFile.FileName=="")
    {
    lbinfo.Text="请选择你要上传的文件!!";
    return;
    }
    try
    {
    char[] spliter={'\\'};
    string [] filename = textfileup.PostedFile.FileName.Split(spliter,10);
    string fullpath = currentpath+@"\"+filename[filename.Length-1];//生成完整的文件名
    textfileup.PostedFile.SaveAs(fullpath);  //保存文件
    loaddir(currentpath);  //重新载入当前目录
    }
    catch
    {
    lbinfo.Text="对不起,上传文件失败!";
    }
      

  3.   

    public static bool UploadFile(HtmlInputFile file,string fileName)
    {
    string filePath = System.Configuration.ConfigurationSettings.AppSettinsUploadAddres"];
    if(!System.IO.Directory.Exists(filePath))
    {
    System.IO.Directory.CreateDirectory(filePath);
    }
    filePath += "\\"+fileName;
    try
    {
    file.PostedFile.SaveAs(filePath);
    return true;
    }
    catch
    {
    return false;
    }
    }
    public static  void DownloadFile(string FileID)
    {
    string FileName = DocManageBll.GetDeptFileName(FileID);
    string physicalFilePath = System.Configuration.ConfigurationSettings.AppSettings["UploadAddres"]+"\\"+FileName;
    if(FileName=="" || GetDeptFileShowName=="")
    return ;
    try 
    {
    stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    int bufSize = (int)stream.Length;
    byte[] buf = new byte[bufSize];
    int bytesRead = stream.Read(buf, 0, bufSize);
    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.AddHeader("Content-Disposition","attachment; filename=\"" + HttpUtility.UrlEncode(GetDeptFileShowName,System.Text.Encoding.UTF8) + "\""); HttpContext.Current.Response.End();
    stream.Close();
    }
    finally
    {                                                                                                

    }
    }
      

  4.   

    http://blog.csdn.net/CQP/archive/2006/08/07/1034079.aspx
      

  5.   

    大哥们,我要得不是asp中的上传和下载,
    我是在.net下做的c/s结构,文挡管理中的把电子文档放到数据库中
    ,请各位帮帮忙
      

  6.   

    private static void SaveBinaryFile(WebResponse response)
    {
    byte[] buffer=new byte[1024];
    string filename=@"c:\temp.exe";
    Stream oustr=File.Create(filename);
    Stream instr=response.GetResponseStream();
    int i;
    do
    {
    i=instr.Read(buffer,0,buffer.Length);
    if(i>0)
    oustr.Write(buffer,0,i);


    }
    while(i>0);
    oustr.Close();
    instr.Close();
    System.Diagnostics.Process.Start(filename);
    }
    private static bool GetBinaryFile()
    {
    HttpWebRequest request=null;
    HttpWebResponse response=null;
    Stream stream=null;
    StreamReader reader=null;
    string URL=@"http://126.com";
    try
    {
    Uri uri=new Uri(URL);
    request=(HttpWebRequest)WebRequest.Create(uri);
    response=(HttpWebResponse)request.GetResponse();
    if(!request.HaveResponse)
    {
    return false;
    }
    if(response.StatusCode!=HttpStatusCode.OK)
    {
    return false;
    }
    SaveBinaryFile(response);
    return true;
    }
    catch(Exception err)
    {
    return false;
    }
    finally
    {
    if(reader!=null)
    reader.Close();
    if(stream!=null)
    stream.Close();
    if(response!=null)
    response.Close();
    }
    }