用aspx读取文件输出它
string strFile = "e:\\test.doc";
FileStream fs = new FileStream(strFile, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" & strFile);
Response.BinaryWrite(bytes);
Response.End();

解决方案 »

  1.   

    Dim name As String = "中文名称"
                Response.ContentType = "application/ms-word"
                Response.Charset = "UTF-8"
                Response.AddHeader("content-disposition", "attachment; filename= " & HttpUtility.UrlEncode(name) & ".doc")            Dim sourceFile As IO.FileStream = New IO.FileStream("F:\downloadexample.doc", IO.FileMode.Open)
                Dim FileSize As Long
                FileSize = sourceFile.Length
                Dim getContent() As Byte = New Byte(FileSize) {}            sourceFile.Read(getContent, 0, sourceFile.Length)
                Response.BinaryWrite(getContent)
                sourceFile.Close()
      

  2.   

    给你一段VB的程序,自己转化为C#的
     Dim fs As FileStream = File.OpenRead(Server.MapPath(filepath.ToString())
    Dim data(fs.Length) As Byte
    fs.Read(data, 0, CInt(fs.Length))
     Dim ext = path.GetExtension(fullpath)
                Dim type As String = ""
                If Not IsDBNull(ext) Then
                    ext = LCase(ext)
                End If
                Select Case ext
                    Case ".htm", ".html"
                        type = "text/HTML"
                    Case ".txt"
                        type = "text/plain"
                    Case ".doc", ".rtf"
                        type = "Application/msword"
                    Case ".csv", ".xls"
                        type = "Application/x-msexcel"
                    Case ".zip", ".msi", ".exe"
                        type = "Application"
                    Case Else
                        type = "Application/octet-stream"
                End Select
      Response.Buffer = True
                Response.Clear()
                If type <> "" Then
                    Response.ContentType = type
                End If
                Response.AddHeader("Content-Disposition", "attachment;filename=" & Replace(filepath.ToString(), _portalSettings.UploadDirectory, ""))
                Response.BinaryWrite(data)
                Response.End()
      

  3.   

    Response.WriteFile()即可
    Response.End()也不需要最好把这个页面的html代码清空Response.AddHeader("Content-Disposition", "attachment;filename=" & strFile);
    之前最好先将strFile = Server.UrlEncode(strFile);
      

  4.   

    三句就够了string file = 文件名;
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file));
    Response.WriteFile(文件完整路径);