web
You’re offline. This is a read only version of the page.
close
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?

I have the same question (0)
  • Community Member Profile Picture
    on at

    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

  • Community Member Profile Picture
    on at

    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. 

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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/

  • Daniel Schumacher Profile Picture
    40 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 45 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Soundari Profile Picture

Soundari 15

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans