Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
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,964 Super User 2024 Season 1 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans