Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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."
 
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)
 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 29-Jan-13 0:13am
Comments
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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..
  Permalink  
Comments
Sunil Bansode at 30-Jan-13 6:33am
   
Thanks..
kshitij_CodeMaster at 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)

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 267
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 162
0 Nirav Prabtani 284
1 OriginalGriff 207
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 119


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100