Skip to main content

Notifications

Announcements

No record found.

Customer Service forum
Suggested answer

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

Posted on by Microsoft Employee

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?

  • 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
    Bipin D365 28,960 Super User 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans