Imports Microsoft.VisualBasic
Imports Office
Imports System.ComponentModel
Imports System.Runtime.InteropServices.Marshal
Imports System.IO
Imports Microsoft.Win32
Public Class responsefile
Sub DownloadFile(ByVal filename As String, ByVal name1 As String)
Dim saveFileName As String = "test.xls"
Dim intStart As Integer = filename.LastIndexOf("\\") + 1
saveFileName = filename.Substring(intStart, filename.Length - intStart)
Dim fi As System.IO.FileInfo = New System.IO.FileInfo(filename)
fi.IsReadOnly = True
Dim fileextname As String = fi.Extension
Dim DEFAULT_CONTENT_TYPE As String = "application/ms-excel"
Dim regkey, fileextkey As RegistryKey
Dim filecontenttype As String
Try
regkey = Registry.ClassesRoot
fileextkey = regkey.OpenSubKey(fileextname)
filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString()
'Response.Clear()
'Response.Charset = "utf-8"
'Response.Buffer = True
'Me.EnableViewState = False
'Response.ContentEncoding = System.Text.Encoding.UTF8
'Response.AppendHeader("Content-Disposition", "attachment;filename=" + name1)
'Response.ContentType = filecontenttype
'Response.WriteFile(filename)
'Response.Flush()
'Response.Close()
'Response.End()
Catch
filecontenttype = DEFAULT_CONTENT_TYPE
End Try
End Sub
End Class