用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();
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();
解决方案 »
- jquery 插入行
- Repeater控件取值的小问题
- 用javascript实现对多个CheckBox的选中
- 异常详细信息: System.Threading.ThreadAbortException: 正在中止线程。
- 怎么样删除文件夹下图片?
- vs.net 2005 asp.net 预编译问题
- F:\Inetpub\wwwroot\patrolSystem\licenses.licx 未能将许可证文件“licenses.licx”转换为二进制资源。(1) : error LC0004 : Exception
- 100分求解操作Excel表的问题,谢谢(c#)
- 200分求:一个简单的聊天室源码(VS2005/C#),最好没有页面刷新的
- 有谁调试成功过 Google API ?
- 如何取datagri编辑框的值?
- 在:ASP。NET下如何作地图?
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()
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()
Response.End()也不需要最好把这个页面的html代码清空Response.AddHeader("Content-Disposition", "attachment;filename=" & strFile);
之前最好先将strFile = Server.UrlEncode(strFile);
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file));
Response.WriteFile(文件完整路径);