locked
Help Plzz... file Dowloading from server ASP.NET VB RRS feed

  • Question

  • User-1232007071 posted

    I want to download files from directory C:\EResource

    the file name is "myFile.text" I have a code

    Code

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            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 Sub


    In the page event handler I have code

    Code

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'Set the appropriate ContentType.
      Response.ContentType = "Application/pdf";
            'Get the physical path to the file.  giving an error here that '.' expected
      string path = MapPath("acrobat.pdf");
            'Write the file directly to the HTTP content output stream.
      Response.WriteFile(FilePath);
      Response.End();

        End Sub


    Error

    Path is not defined

    fname is not declared

    forcedownload is not declared

    filepath is not declared


    Wednesday, August 26, 2009 4:10 AM

Answers

  • User-1659704165 posted

    Hi,

    Just Declare the follwing Line After name space had beeen declared..

    Dim path As Path
            Dim fullpath = path.GetFullPath(fname)
            Dim name = path.GetFileName(fullpath)
            Dim ext = path.GetExtension(fullpath)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2009 6:58 AM