Click here to Skip to main content
Sign Up to vote bad
good
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:13

Comments
Sergey Alexandrovich Kryukov - 29 Jan '13 - 6:20
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

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 - 30 Jan '13 - 6:33
Thanks..
kshitij_CodeMaster - 30 Jan '13 - 7:18
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 315
1 Aarti Meswania 250
2 Slacker007 240
3 Sergey Alexandrovich Kryukov 219
4 Ron Beyer 190
0 Sergey Alexandrovich Kryukov 8,743
1 OriginalGriff 7,124
2 CPallini 3,678
3 Rohan Leuva 3,011
4 Maciej Los 2,403


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid