Error when downloading a picture from URL to a file on disk

  • Thread starter Thread starter YigalB
  • Start date Start date
Y

YigalB

Guest
I am trying to download pictures, with URL for every picture, and save them to disk.

I am using this code which I found as an example:

WebClient webClient = new WebClient();
webClient.DownloadFile(pic_file_url, docPath + "\\Gedcom\\" + "Pic.jpg");


The pic file URL has a picture - I can see it (after removing the double backslash, yet I get error 403. What is wrong with the code? Is there a better way to download pictures?



System.Net.WebException
HResult=0x80131509
Message=The remote server returned an error: (403) Forbidden.
Source=System
StackTrace:
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at WindowsFormsApp5.Print_class.Print_Indi_to_word(Persons _personsList) in C:\Users\yigal\Documents\Yigal\VS2017\Repos\BZfamTree\WindowsFormsApp5\Print class.cs:line 170
at WindowsFormsApp5.Form1.ReadFile() in C:\Users\yigal\Documents\Yigal\VS2017\Repos\BZfamTree\WindowsFormsApp5\Form1.cs:line 220
at WindowsFormsApp5.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\yigal\Documents\Yigal\VS2017\Repos\BZfamTree\WindowsFormsApp5\Form1.cs:line 310
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApp5.Program.Main() in C:\Users\yigal\Documents\Yigal\VS2017\Repos\BZfamTree\WindowsFormsApp5\Program.cs:line 19

Continue reading...
 

Similar threads

M
Replies
0
Views
114
Mani25
M
N
Replies
0
Views
99
Narayan Pinamaraju
N
D
Replies
0
Views
91
Decompressor
D
G
Replies
0
Views
160
Graham Skan
G
Back
Top