CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2001
    Posts
    365

    File downloading problem

    Hi

    I am trying to download the PDF files from my webserver using ASP.Net

    All my files are stored at F Drive on webserver. Like this F:\Main Folder\Sub Folder\Files\File1.pdf

    I am impersonating the domain user account and downloading the file, It seems the impersonate is got success, but its not download the file. Some time its simply downloading some junk pdf file instead of original file.

    I gave the all permission to Main Folder for all the domain users.

    Here is the code which I am using in my application.



    Code:

    If impersonateValidUser(Session("WinLogin"), "domainName", Session("WinPassword")) Then
    DownloadFile(CType(E.Item.Cells(0).Controls(0), HyperLink).NavigateUrl, True)
    Else
    Response.Write("not ok")
    End If

    -----------

    Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As
    Boolean)
    Dim path1 As String = fname
    Dim name As String = Path.GetFileName(path1)

    Dim ext As String = Path.GetExtension(path1)
    Dim type As String = "Application/pdf"
    If forceDownload Then
    Response.AppendHeader("content-disposition", "attachment; filename=" & name)
    Else
    Response.AppendHeader("content-disposition", "inline; filename=" & name)
    End If
    Response.WriteFile(path1)
    End Sub

  2. #2
    Join Date
    Dec 2002
    Location
    Myanmar
    Posts
    84

    Re: File downloading problem

    You might need to use "type" variable you have declared and assigned. You need to assign it into Response.ContentType.
    Then test it again.
    If you still have problem, Just change your code to use Response.BinaryWrite() instead of Response.WriteFile().
    Let's go together
    _columbus2003_

  3. #3
    Join Date
    Jan 2001
    Posts
    365

    Re: File downloading problem

    Hi

    Thanks for the reply.

    The response.ContentType not working and also I know the filename with full path, I dont know how to use the BinaryWrite. Can you please help me how to use the binarywrite in my situation.

    Thanks
    Balakumar

  4. #4
    Join Date
    Jan 2001
    Posts
    365

    Re: File downloading problem

    hey man, You are the great. Thank you so much. Its working fine now.

    I used the below code....

    Dim MyFileStream As FileStream
    Dim FileSize As Long

    MyFileStream = New FileStream(path1, FileMode.Open)
    FileSize = MyFileStream.Length

    Dim Buffer(CInt(FileSize)) As Byte
    MyFileStream.Read(Buffer, 0, CInt(FileSize))
    MyFileStream.Close()
    Response.BinaryWrite(Buffer)

    Thanks
    Balakumar

  5. #5
    Join Date
    Dec 2002
    Location
    Myanmar
    Posts
    84

    Re: File downloading problem

    Code:
    Dim MyFileStream As FileStream
    Dim FileSize As Long
     
    MyFileStream = New FileStream(fname, FileMode.Open)
    FileSize = MyFileStream.Length
     
    Dim Buffer(CInt(FileSize)) As Byte
    MyFileStream.Read(Buffer, 0, CInt(FileSize))
    MyFileStream.Close()
     
    Response.BinaryWrite(Buffer)
    I just copied and edited the sample code from msdn...
    Let's go together
    _columbus2003_

  6. #6
    Join Date
    Jan 2001
    Posts
    365

    Re: File downloading problem

    Thank you so much.

    balakumar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured