Click here to Skip to main content
15,886,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Respected sir,
i am using following code for download some file from url
but i get error like
" The remote server returned an error: (403) Forbidden."

VB
Dim sSourceUrl As String 
Dim DownFilePath As String
sSourceUrl = "http://www.nseindia.com/archives/equities/mto/MTO_17012013.DAT"
DownFilePath = "C:\abc.txt"

DownloadFile(sSourceUrl, DownFilePath)

VB
Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)
       Try
           Dim _WebClient As New System.Net.WebClient()
           WebClient.DownloadFile(_URL, _SaveAs)

       Catch _Exception As Exception
          MsgBox(_Exception.Message)
       End Try
   End Sub


Is there another way to do this,
Please help me,
Thank you
Posted
Comments
Sergey Alexandrovich Kryukov 29-Jan-13 6:20am    
It's forbidden. The way does not matter here.
However: will you be able to download same thing using some available tool, like a Web browser?
Does it need authentication?
—SA

1 solution

VB
Protected Sub btnCopy_Click(sender As Object, e As EventArgs)
    Try
        
            Dim filename As String = "abcd.mp3"
            Dim sourcePath As String = "\\is-pc634\Shared\"



        '--------Download Option-----------
            Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
            response.ClearContent()
            response.Clear()
            response.ContentType = "audio/x-wav"
            response.AddHeader("Content-Disposition", "attachment; filename=" & fileName & ";")
            response.TransmitFile(sourcePath)
            response.Flush()

            response.End()
        Else
            msgBox("File cannot be downloaded.")
        End If
    Catch ex As Exception
        msgBox(ex.Message)
    End Try

End Sub



hope it helps u..
 
Share this answer
 
Comments
Sunil Bansode 30-Jan-13 6:33am    
Thanks..
[no name] 30-Jan-13 7:18am    
ur welcome buddy :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900