Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested answer

Error when retreiveing file contents from on-premise file type field

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a 9.1 On-Premise instance of Dynamics 365 which I am trying to add a File data type field to a custom entity. I hav added the field successfully and I am now trying to retrieve and read the contents of the file in the PostUpdate plugin.

I have the following C# code which I found from various supporting places which is supposed to work:

InitializeFileBlocksDownloadRequest initializeFile = new InitializeFileBlocksDownloadRequest();
initializeFile.FileAttributeName = CRMConstants.RECEIPTING_PAYMENTS_FILE;
initializeFile.Target = new EntityReference(CRMConstants.RECEIPTING_PAYMENTS_LOGICAL_NAME, receiptingPaymentsEntity.Id);

InitializeFileBlocksDownloadResponse initializeFileResponse = (InitializeFileBlocksDownloadResponse)service.Execute(initializeFile);
var fileContinuationToken = initializeFileResponse.FileContinuationToken;

// code to downlod the file.
DownloadBlockRequest downloadRequest = new DownloadBlockRequest();
downloadRequest.Offset = 0;
downloadRequest.BlockLength = (long)4 * 1024 * 1024; // can be max of 4 MB
downloadRequest.FileContinuationToken = fileContinuationToken;

DownloadBlockResponse downloadBlockResponse = (DownloadBlockResponse)service.Execute(downloadRequest);

The last line throws the error: 

Downloading in multiple chunks is not supported for the files stored in the database.'

Has anyone got any ideas on what I am doing wrong or how to correct the code to avoid chunking?

  • Daniel Schumacher Profile Picture
    40 on at
    RE: Error when retreiveing file contents from on-premise file type field

    I've had the same issue. Bipin Kumar  your suggestion solved this issue for me. Thank you

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Error when retreiveing file contents from on-premise file type field

    Hi,

    Could you please try below code.

    // Download file
                            var initializeFile = new InitializeFileBlocksDownloadRequest
                            {
                                FileAttributeName = "cr127_filecolumn",
                                Target = employee.ToEntityReference()
                            };
                            var fileResponse = (InitializeFileBlocksDownloadResponse)service.Execute(initializeFile);
                            var req = new DownloadBlockRequest { FileContinuationToken = fileResponse.FileContinuationToken, BlockLength = fileResponse.FileSizeInBytes };
                            var response = (DownloadBlockResponse)service.Execute(req);

    I have verified this code on Online instance and it works as expected. Please verify it on your onpremise instance.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Community Member Profile Picture
    on at
    RE: Error when retreiveing file contents from on-premise file type field

    Hi Leah,

    That post is using client side code, I got my server side code example from his other post:

    debajmecrm.com/.../

    I have copied it line by line, but it doesn't work for me. 

  • Community Member Profile Picture
    on at
    RE: Error when retreiveing file contents from on-premise file type field

    Hi Rodney,

    Maybe you can refer following link:

    community.dynamics.com/.../retrieve-contents-of-file-data-type-field-in-dynamics-365-cds-using-javascript-client-code

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#2
Ramesh Kumar Profile Picture

Ramesh Kumar 42

#3
David Shaw_UK Profile Picture

David Shaw_UK 27

Featured topics

Product updates

Dynamics 365 release plans