title: Download DWG files on asp classic
body: <p>I need download files from folder on the server.</p>
  
  <p>I have tried this code in ASP Classic, but when the file is DWG the download not working.</p>
  
  <p>I don't have error, this code downloading all files type is out for DWG files.</p>
  
  <p>Can anybody help me?</p>
  
  <p>Thanks in advance.</p>
  
  <p>My code below.</p>
  
  <p><strong>getfile.asp</strong></p>
  
  <pre><code>&lt;%
  Function BaseName(byVal Path)
  Dim Pos
      Path = Replace(Path,"/","\")
      Pos  = InStrRev(Path,"\")
      If Pos&gt;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&lt;&gt;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"))) &gt; 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=" &amp; BaseName(file)
  Response.BinaryWrite ReadFile(File)
  Response.End
  %&gt;
  </code></pre>
  
  <p><strong>default.asp</strong></p>
  
  <pre><code>    &lt;script language="JavaScript" type="text/javascript"&gt;
      function doDownload(file1, file2, frmName)
      {
        var ifrmObj = document.getElementById((frmName &amp;&amp; frmName.length &gt; 0) ? frmName : "dwnFrm1");
        ifrmObj.src = "";
        ifrmObj.src = "getFile.asp?file=" + file1;
  
        if (!file2 || file2.length &lt;= 0) return;
  
        // Timeout
        window.setTimeout("doDownload('" + file2 + "', '', 'dwnFrm2');", 3000);
      }
      &lt;/script&gt;
  
      &lt;body bgcolor="#EAEFFF"&gt;
  
      &lt;iframe id="dwnFrm1" style="display: none;"&gt;&lt;/iframe&gt;
      &lt;iframe id="dwnFrm2" style="display: none;"&gt;&lt;/iframe&gt;
  
      extDWG = right(directoryfile.Name, 3)
      if extDWG = "dwg" then           
         response.write ("&lt;a href=""javascript:void(0);"" onclick=""doDownload('/MyFolder/" &amp; Server.HTMLencode(folder) &amp; "/"&amp; Server.HTMLencode(directoryfile.Name) &amp;"', '/MyFolder/" &amp; Server.HTMLencode(folder) &amp; "/X-cart.dwg');""&gt;")    
      else    
         response.write ("&lt;a href=""/MyFolder/" &amp; folder &amp; "/"  &amp; directoryfile.Name &amp;"""&gt;")    
      end if
  </code></pre>