web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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,985 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 51 Super User 2026 Season 1

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#3
Nagaraju_Matta Profile Picture

Nagaraju_Matta 50

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans