Solved

downloading a linked file from an asp,net website

Posted on 2011-09-08
10
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

631 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