我是写ASP的,是.net盲
我想问一下在.net里,对于上传文件如何打开,是直接把文件路径做连接吗?
在ASP中有诸如以下的代码,用来打开上传文件,我想问在.net里有吗?
<%
Option Explicit 
On Error Resume NextDim sPath, oFso, oSt, oFile, iSizeIf Request.QueryString.Count<1 Then Response.End()
sPath = unescape(Request.QueryString)
Set oFso = Server.CreateObject("Scripting.FileSystemObject")
Set oSt = Server.CreateObject("ADODB.Stream")Set oFile = oFso.GetFile(sPath)
iSize = oFile.SizeoSt.Mode = 3
oSt.Type = 1
oSt.Open()
oSt.LoadFromFile(sPath)Response.AddHeader "Content-Disposition", "attachment; filename=" & oFile.Name
Response.AddHeader "Content-Length", iSize
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(oSt.Read())Set oSt = Nothing
Set oFso = Nothing
%>

解决方案 »

  1.   

    我刚才发的是一个download页的代码?ASP中这样写<a href=../com/download.asp?<%=dir&replace(trim(rs("E_FILE")),"../","")%>" target="_blank">111</a> 
    就想求一个.net中如download页功能的代码?
    公司急用!!
    谢谢大家了
      

  2.   

    System.IO.FileInfo file = new System.IO.FileInfo("F:\\我们的爱.mp3");
    Response.Clear();
    Response.ClearHeaders();
    Response.Buffer = false;
    Response.Charset="GB2312";
    Response.ContentEncoding=System.Text.Encoding.UTF8;
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename="+Server.UrlPathEncode("我们的爱.mp3"));
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.WriteFile(file.FullName);
    Response.Flush();
    Response.End();