How to download file

  • Thread starter Thread starter Tim McGavin
  • Start date Start date
T

Tim McGavin

When I make a link like this on my page...

http://www.domain.com/file1.smp

I get "page not displayed". The extension SMP is not a typical extension.
It needs to launch a local application. Similar to the way a DOC extension
would launch word.

Do I need to use ASP to do this? It seems to me that I should be able to
make this happen using just HTML.

Thanks!!
 
What local application is launched depends on the user's browser settings,
so for the most part you cannot control what application is launched. If you
want the file to be downloaded (which is what I am guessing you are asking
based on the subject), you will need to use a few methods of the Response
object. Here are some of the most important ones:


Response.ClearContent()
Response.ContentType (I have included a function below to help determine
the value for this)
Response.AddHeader("content-disposition", "attachment;filename=" &
txtFileToDownload.Text) (see the documentation for more details on the
parameters for this method)
Response.WriteFile()
Response.End()


Here is a function to help you determine the value for Response.ContentType:

Public Function GetMimeType(ByVal extension As String) As String
Dim regkey As Microsoft.Win32.RegistryKey =
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension.ToLower())
If regkey IsNot Nothing AndAlso regkey.GetValue("Content Type") IsNot
Nothing Then
Return CStr(regkey.GetValue("Content Type"))
Else
Return ""
End If
End Function


Hopefully all this will help you accomplish whatever you needed. Good Luck!
 
Back
Top