none
Error when downloading a picture from URL to a file on disk RRS feed

  • Question

  • 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
    

    Saturday, March 16, 2019 5:37 PM

Answers

  • I was login to that site on Chrom, so I checked your theory on IE - and I could see the pic.

    Here is the content of pic_file_url definition:

    static string pic_file_url = "http://photos.geni.com//p9//3152//1809//53444837dcc24f95//Abraham_Zeff_original.jpg?no_ssl=true";


    Try replacing (manually) all of “//” with “/”, excepting “http://”.

    • Marked as answer by YigalB Saturday, March 16, 2019 7:48 PM
    Saturday, March 16, 2019 7:29 PM

All replies

  • Maybe you see the image in browser only if you are signed in to Web application.

    If possible, give an example of pic_file_url that does not work.


    • Edited by Viorel_MVP Saturday, March 16, 2019 6:11 PM
    Saturday, March 16, 2019 6:10 PM
  • I was login to that site on Chrom, so I checked your theory on IE - and I could see the pic.

    Here is the content of pic_file_url definition:

    static string pic_file_url = "http://photos.geni.com//p9//3152//1809//53444837dcc24f95//Abraham_Zeff_original.jpg?no_ssl=true";
    

    Saturday, March 16, 2019 7:11 PM
  • I was login to that site on Chrom, so I checked your theory on IE - and I could see the pic.

    Here is the content of pic_file_url definition:

    static string pic_file_url = "http://photos.geni.com//p9//3152//1809//53444837dcc24f95//Abraham_Zeff_original.jpg?no_ssl=true";


    Try replacing (manually) all of “//” with “/”, excepting “http://”.

    • Marked as answer by YigalB Saturday, March 16, 2019 7:48 PM
    Saturday, March 16, 2019 7:29 PM
  • Try replacing (manually) all of “//” with “/”, excepting “http://”.

    It is working. Great!

    Actually I was the one that inserted the additional "/", assuming same practice like the file path.

    Thank you!

    Saturday, March 16, 2019 7:48 PM