心有多高,就飞多高

天高任鸟飞

博客园 首页 联系 订阅 管理

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

posted on 2007-03-08 11:21  lankoboy  阅读(186)  评论(0编辑  收藏  举报