Solved

downloading a linked file from an asp,net website

Posted on 2011-09-08
10
372 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 39

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 39

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
 
LVL 1

Author Comment

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

Expert Comment

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


try this:
  hl.NavigateUrl = "/docs/" + drd("d_FileToUpload")
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 39

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now