【问题标题】:Download DWG files on asp classic在 asp classic 上下载 DWG 文件
【发布时间】:2017-05-09 10:36:10
【问题描述】:

我需要从服务器上的文件夹下载文件。

我已在 ASP Classic 中尝试过此代码,但当文件为 DWG 时,无法下载。

我没有错误,此代码下载所有文件类型不适用于 DWG 文件。

谁能帮帮我?

提前致谢。

下面是我的代码。

getfile.asp

<%
Function BaseName(byVal Path)
Dim Pos
    Path = Replace(Path,"/","\")
    Pos  = InStrRev(Path,"\")
    If Pos>0 then 
        BaseName = Mid(Path,Pos+1)
    Else
        BaseName = Path
    End if
end function

Function ReadFile(FileName)
Dim Stream , Path
    On error resume next
        Path = Server.MapPath(FileName)
        If Err.Number<>0 then Path = FileName
    On error goto 0
    Set Stream = Server.CreateObject("ADODB.Stream")
    Stream.Type=1
    Stream.Open()
    Stream.LoadFromFile Path
    Stream.Position=0
    ReadFile = Stream.Read()
    Stream.Close()
    Set Stream = Nothing
End Function

' Timeout
Server.ScriptTimeout=6000
if Len(Trim(request.querystring("file"))) > 0 then
    file = server.mappath(request.querystring("file")) 
else
    Response.Write("file not found")
    Response.end
end if
response.ContentType="application/octet-stream"
response.AddHeader "Content-Disposition", "attachment; filename=" & BaseName(file)
Response.BinaryWrite ReadFile(File)
Response.End
%>

default.asp

    <script language="JavaScript" type="text/javascript">
    function doDownload(file1, file2, frmName)
    {
      var ifrmObj = document.getElementById((frmName && frmName.length > 0) ? frmName : "dwnFrm1");
      ifrmObj.src = "";
      ifrmObj.src = "getFile.asp?file=" + file1;

      if (!file2 || file2.length <= 0) return;

      // Timeout
      window.setTimeout("doDownload('" + file2 + "', '', 'dwnFrm2');", 3000);
    }
    </script>

    <body bgcolor="#EAEFFF">

    <iframe id="dwnFrm1" style="display: none;"></iframe>
    <iframe id="dwnFrm2" style="display: none;"></iframe>

    extDWG = right(directoryfile.Name, 3)
    if extDWG = "dwg" then           
       response.write ("<a href=""javascript:void(0);"" onclick=""doDownload('/MyFolder/" & Server.HTMLencode(folder) & "/"& Server.HTMLencode(directoryfile.Name) &"', '/MyFolder/" & Server.HTMLencode(folder) & "/X-cart.dwg');"">")    
    else    
       response.write ("<a href=""/MyFolder/" & folder & "/"  & directoryfile.Name &""">")    
    end if

【问题讨论】:

    标签: download asp-classic dwg


    【解决方案1】:

    您需要在服务器上为 dwg 文件添加 mime 类型。

    不常见的文件扩展名通常没有关联。

    • 在较旧的 IIS(版本 6/7)中,您可以在 IIS 管理器中右键单击服务器并选择属性,然后单击 MIME 类型按钮。在这里,您需要为具有正确 mime 类型的 .dwg 文件添加记录。
    • 在 IIS 8 中,单击 IIS 管理器中的站点名称,然后选择 MIME 类型。然后以相同的方式添加,如下所述:

    按 new 并取决于扩展类型,在你的情况下,我在短暂的谷歌搜索后猜想 .dwg 应该有 application/acad 作为 mime 类型。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-27
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 2016-11-30
      相关资源
      最近更新 更多