我上传了一个WORD文件到d盘 d:\mydoc\111.doc  请问如何通过程序下载下来呢?

解决方案 »

  1.   

    public static void DownloadFile(string physicalFilePath)
    {
                FileStream stream=null;
                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.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
                    HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
                    HttpContext.Current.Response.End();
                }
                finally 
                {
                    stream.Close();
                }
    }private void btndownload_Click(object sender, System.EventArgs e)
    {
          DownloadFile(@"d:\mydoc\111.doc");      
    }
      

  2.   

    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -i
    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -c