4 个解决方案
#1
怎么没有人回答?
#2
好象做不到。除非告诉用户点右键另存为...嘿嘿。
#3
有人会吗?
#4
试试这个:
实现文件下载而不是由ie打开的代码。
--------- hooke
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k
'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess
'Server.MapPath(path)
path = "C:\Inetpub\wwwroot\help.gif"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"help.gif")
Response.End
%>
另有我知道两种方法,你试一试吧
一.
<%
fn="thefilenametosave"
Response.AddHeader "Content-Disposition: ","attachment;filename="&fn
%>
<!--#include file="thefilewilldown.txt"-->
二.
Response.ContentType="appliaction/x-txt" '这行用来确定MIME,视数据内容而定
Response.AddHeader "content-disposition", "attachment;filename=纪事.txt"
'这行用于指定用户保存时缺省文件名
'以下是数据
set fs=server.CreateObject("Scripting.FileSystemObject")
cfile=Server.MapPath("../template/"&session("userid")&"/"&filename)
set txtfile=fs.OpenTextFile(cfile)
cTxt=txtfile.ReadAll
Response.Write cTxt
txtfile.close
set fs=nothing
Response.End
实现文件下载而不是由ie打开的代码。
--------- hooke
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k
'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess
'Server.MapPath(path)
path = "C:\Inetpub\wwwroot\help.gif"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"help.gif")
Response.End
%>
另有我知道两种方法,你试一试吧
一.
<%
fn="thefilenametosave"
Response.AddHeader "Content-Disposition: ","attachment;filename="&fn
%>
<!--#include file="thefilewilldown.txt"-->
二.
Response.ContentType="appliaction/x-txt" '这行用来确定MIME,视数据内容而定
Response.AddHeader "content-disposition", "attachment;filename=纪事.txt"
'这行用于指定用户保存时缺省文件名
'以下是数据
set fs=server.CreateObject("Scripting.FileSystemObject")
cfile=Server.MapPath("../template/"&session("userid")&"/"&filename)
set txtfile=fs.OpenTextFile(cfile)
cTxt=txtfile.ReadAll
Response.Write cTxt
txtfile.close
set fs=nothing
Response.End
#1
怎么没有人回答?
#2
好象做不到。除非告诉用户点右键另存为...嘿嘿。
#3
有人会吗?
#4
试试这个:
实现文件下载而不是由ie打开的代码。
--------- hooke
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k
'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess
'Server.MapPath(path)
path = "C:\Inetpub\wwwroot\help.gif"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"help.gif")
Response.End
%>
另有我知道两种方法,你试一试吧
一.
<%
fn="thefilenametosave"
Response.AddHeader "Content-Disposition: ","attachment;filename="&fn
%>
<!--#include file="thefilewilldown.txt"-->
二.
Response.ContentType="appliaction/x-txt" '这行用来确定MIME,视数据内容而定
Response.AddHeader "content-disposition", "attachment;filename=纪事.txt"
'这行用于指定用户保存时缺省文件名
'以下是数据
set fs=server.CreateObject("Scripting.FileSystemObject")
cfile=Server.MapPath("../template/"&session("userid")&"/"&filename)
set txtfile=fs.OpenTextFile(cfile)
cTxt=txtfile.ReadAll
Response.Write cTxt
txtfile.close
set fs=nothing
Response.End
实现文件下载而不是由ie打开的代码。
--------- hooke
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k
'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess
'Server.MapPath(path)
path = "C:\Inetpub\wwwroot\help.gif"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"help.gif")
Response.End
%>
另有我知道两种方法,你试一试吧
一.
<%
fn="thefilenametosave"
Response.AddHeader "Content-Disposition: ","attachment;filename="&fn
%>
<!--#include file="thefilewilldown.txt"-->
二.
Response.ContentType="appliaction/x-txt" '这行用来确定MIME,视数据内容而定
Response.AddHeader "content-disposition", "attachment;filename=纪事.txt"
'这行用于指定用户保存时缺省文件名
'以下是数据
set fs=server.CreateObject("Scripting.FileSystemObject")
cfile=Server.MapPath("../template/"&session("userid")&"/"&filename)
set txtfile=fs.OpenTextFile(cfile)
cTxt=txtfile.ReadAll
Response.Write cTxt
txtfile.close
set fs=nothing
Response.End