Solved

downloading a linked file from an asp,net website

Posted on 2011-09-08
10
383 Views
Last Modified: 2012-05-12
I am using this code to upload a file to a website and it works fine
but when i try to download the file using the code as below it shows the link like and doesnot respond when you try to open it.

'link that shows
http://localhost:54753/cbha/reviewDocuments.aspx?file=C:\cbha\docs\System%20login.docx

'code to download

 Dim hl As New HyperLink

       
        hl.ID = "file" & ii

        hl.Text = drd("d_FileToUpload") & ""
        hl.NavigateUrl = "reviewDocuments.aspx?file=" + Server.MapPath("docs\" & drd("d_FileToUpload"))
        tc.Controls.Add(hl)
        tr.Cells.Add(tc)
        tb.Rows.Add(tr)

        ftc.Controls.Add(tb)
        ftr.Cells.Add(ftc)
        Me.d_table.Rows.Add(ftr)



'code to upload
 If d_FileToUpload.HasFile Then
                Try
                    If d_FileToUpload.PostedFile.ContentLength > 4000000 Then
                        Me.Label1.Text = "File size maximum is 4mbs)- file not uploaded:"
                        Exit Sub
                    End If
                    d_FileToUpload.SaveAs(Server.MapPath("docs\" & d_FileToUpload.FileName))
                    Label1.Text = "File: " & _
                       d_FileToUpload.PostedFile.FileName & " has been uploaded<br>"
                Catch ex As Exception
                    Label1.Text = "ERROR: " & ex.Message.ToString()
                End Try
            Else
                Label1.Text = "You have not specified a file."
0
Comment
Question by:Anthony Matovu
  • 5
  • 4
10 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 36503531
 hl.NavigateUrl = Server.MapPath("docs\" & drd("d_FileToUpload"))

what's on teh review documents page?
0
 
LVL 1

Author Comment

by:Anthony Matovu
ID: 36503563
nothing opens
it only shows http://localhost:54753/cbha/reviewDocuments.aspx?file=C:\cbha\docs\System%20login.docx

in the bar where we type the URL

ANTHONY
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 36503570
change the navigateURL to what I have . . . eg: remove the reviewDocuments.Aspx part from your HL link.

can you confirm that

c:\cbha\docs\system login.docx exists?



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Anthony Matovu
ID: 36503669
yes it does exist
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 36503685
did you remove the reviewDocuments part?


try this:
  hl.NavigateUrl = "/docs/" + drd("d_FileToUpload")
0
 
LVL 1

Author Comment

by:Anthony Matovu
ID: 36503792
i have left like \
hl.NavigateUrl = Server.MapPath("docs\" + drd("d_FileToUpload"))
and it only shows "file///c:/cbha/docs/System%20login.docx

below when you pass a cursor over it. but does not respond to a click
a
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 36504563
Remove the server.map path.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36506101
Does reviewDocument.aspx exist? If you put a path like "C:\..." it will try to open the file on the client computer not the server. You can add code the reviewDocument.aspx so that it reads the file and sends it to client.
0
 
LVL 1

Accepted Solution

by:
Anthony Matovu earned 0 total points
ID: 36508249
thank you very much for the guide.

I created a dynamic button and used the code below and it is working

  Protected Sub btn_click(ByVal sender As Object, ByVal e As EventArgs)
        Dim a = CType(sender, Button).ID
        Dim filename As String = Mid(a, a.IndexOf("_") + 2, a.Length)
        Dim ext As String = IO.Path.GetExtension(Server.MapPath("docs\" + filename))
        Dim fname As String = Server.MapPath("docs\" + filename)
        Response.ContentType = ReturnExtension(ext)
        Response.AppendHeader("Content-Disposition", "attachment; filename=" & filename)
        Response.TransmitFile(fname)
        Response.End()
    End Sub
0
 
LVL 1

Author Closing Comment

by:Anthony Matovu
ID: 36527983
It is not a very direct solution to the problem but it is an alternative that works
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question