Hello,
- I have an image in the following path in SharePoint
http://servername/sites/Test/en-us/PublishingImages/activity.png
- 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))
{
Directory.CreateDirectory(destinationPath);
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())
destination.WriteByte((byte)a);
}
}
}
- 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 ?
Thanks
ASk