Retrieve image from MSCRM 2013
First you need to get the service object
to get service object follow the below link:
http://raju2565.blogspot.in/2014/07/mscrm-online-authentication.html
Entity _account = new Entity("account");
string binaryImageQuery = String.Format(@"<fetch mapping='logical'>
<entity name='{0}'>
<attribute name='sample_name' />
<attribute name='entityimage' />
</entity>
</fetch>", _account);
EntityCollection binaryImageResults = service.RetrieveMultiple(new FetchExpression(binaryImageQuery));
Console.WriteLine("Records retrieved and image files saved to: {0}", Directory.GetCurrentDirectory());
foreach (Entity record in binaryImageResults.Entities)
{
String recordName = record["sample_name"] as String;
String downloadedFileName = String.Format("Downloaded_{0}", recordName);
byte[] imageBytes = record["entityimage"] as byte[];
var fs = new BinaryWriter(new FileStream(downloadedFileName, FileMode.Append, FileAccess.Write));
fs.Write(imageBytes);
fs.Close();
Console.WriteLine(downloadedFileName);
}
to get service object follow the below link:
http://raju2565.blogspot.in/2014/07/mscrm-online-authentication.html
Entity _account = new Entity("account");
string binaryImageQuery = String.Format(@"<fetch mapping='logical'>
<entity name='{0}'>
<attribute name='sample_name' />
<attribute name='entityimage' />
</entity>
</fetch>", _account);
EntityCollection binaryImageResults = service.RetrieveMultiple(new FetchExpression(binaryImageQuery));
Console.WriteLine("Records retrieved and image files saved to: {0}", Directory.GetCurrentDirectory());
foreach (Entity record in binaryImageResults.Entities)
{
String recordName = record["sample_name"] as String;
String downloadedFileName = String.Format("Downloaded_{0}", recordName);
byte[] imageBytes = record["entityimage"] as byte[];
var fs = new BinaryWriter(new FileStream(downloadedFileName, FileMode.Append, FileAccess.Write));
fs.Write(imageBytes);
fs.Close();
Console.WriteLine(downloadedFileName);
}
Comments
Post a Comment