公共模块!  
Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
  Dim path As Path
  Dim fullpath = path.GetFullPath(fname)
  Dim name = path.GetFileName(fullpath)
  Dim ext = path.GetExtension(fullpath)
  Dim type As String = ""  If Not IsDBNull(ext) Then
      ext = LCase(ext)
  End If  Select Case ext
      Case ".htm", ".html"
          type = "text/HTML"
      Case ".txt"
          type = "text/plain"
      Case ".doc", ".rtf"
          type = "Application/msword"
      Case ".csv", ".xls"
          type = "Application/x-msexcel"
      Case Else
          type = "text/plain"
  End Select  If (forceDownload) Then
      Response.AppendHeader("content-disposition", _
      "attachment; filename=" + name)
  End If
  If type <> "" Then
      Response.ContentType = type
  End If  Response.WriteFile(fullpath)
  Response.End()
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DownloadFile("c:\12.doc", True)-----------出错地方(提示:"c:\12.doc"路径不对) 
    End Sub
如果我换成:DownloadFile("c:\12.xls", True)格式运行正常!这是错在什么地方?

解决方案 »

  1.   

    公共模块!  
    Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
      Dim path As Path
      Dim fullpath = path.GetFullPath(fname)
      Dim name = path.GetFileName(fullpath)
      Dim ext = path.GetExtension(fullpath)
      Dim type As String = ""  If Not IsDBNull(ext) Then
          ext = LCase(ext)
      End If  Select Case ext
          Case ".htm", ".html"
              type = "text/HTML"
          Case ".txt"
              type = "text/plain"
          Case ".doc", ".rtf"
              type = "Application/msword"
          Case ".csv", ".xls"
              type = "Application/x-msexcel"
          Case Else
              type = "text/plain"
      End Select  If (forceDownload) Then
          Response.AppendHeader("content-disposition", _
          "attachment; filename=" + name)
      End If
      If type <> "" Then
          Response.ContentType = type
      End If  Response.WriteFile(fullpath)--------------这个地方也有问题!
      Response.End()
    End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            DownloadFile("c:\12.doc", True)-----------出错地方(提示:"c:\12.doc"路径不对) 
        End Sub
    如果我换成:DownloadFile("c:\12.xls", True)格式运行正常!这是错在什么地方?
      

  2.   

    c:\\12.xls格式没有问题,但是*.doc的就提示访问被拒绝!