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);
        }

Comments

Popular posts from this blog

Connecting Dynamics 365 Web api using external HTML page

Form State Rule using Ribbon Work bench MSCRM 2013

Get azure blob files inside Sub Directories