download image by client object Model : The remote server returned an error: (404) Not Found RRS feed

  • Question

  • Hello,

    •  I have an image in the following path in SharePoint


    • I write the following code to download image by client object Model :

               ClientContext clientContext = new ClientContext("http://ServerName/sites/Test");
               DownloadFile(clientContext, "/en-us/PublishingImages/", @"C:\Test", "activity.png");           

               public static bool DownloadFile(ClientContext context, string fileRelativeUrl, string destinationPath, string fileName)
                    fileRelativeUrl = fileRelativeUrl.Replace("/Images/", "/PublishingImages/");
                    string sourceUrl = fileRelativeUrl + fileName;
                    string completeDestinationPath = destinationPath + fileName;

                    if (!System.IO.File.Exists(completeDestinationPath))
                        FileInformation spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, sourceUrl);

                        using (Stream destination = System.IO.File.Create(completeDestinationPath))
                            for (int a = spFileInfo.Stream.ReadByte(); a != -1; a = spFileInfo.Stream.ReadByte())

    • When I run the code Th get the following error "The remote server returned an error: (404) Not Found."

          at this line "FileInformation spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, sourceUrl);"

        How Can I solve this error ?



    Wednesday, June 18, 2014 6:57 AM


  • Hi,


    Please check the source url value. Is it formed properly? try to print the value

    Please remember to click 'Mark as Answer' on the answer if it helps you

    • Marked as answer by himo Thursday, June 19, 2014 9:44 AM
    Wednesday, June 18, 2014 7:12 AM

All replies