Solved

downloading a linked file from an asp,net website

Posted on 2011-09-08
10
382 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC identity 6 27
JSON  parse help 7 27
asp.net input html code have it display the content 2 14
How to read text with RegEx... 2 11
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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