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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Upload File to CRM File-Field with C#

(0) ShareShare
ReportReport
Posted on by 5

Hi, I created a file field at powerapps and can upload a file in the CRM formular. Now I need an upload by C# and I found the classes:

InitializeFileBlocksUploadRequest and CommitFileBlocksUploadRequest

Fine except of the "BlockList" at CommitFileBlocksUploadRequest: How to set it correctly within byte-Array or base64 String?

public long UploadFileAsByteArray(ref IOrganizationService service, ref ITracingService tracingService, ref byte[] bytes, string fileName, EntityReference entityReference, string fieldNameOfFile) { string[] blockList = new string[1]; blockList[0] = InfSystem.GetBase64OfByteArray(bytes); InitializeFileBlocksUploadRequest initRequest = new InitializeFileBlocksUploadRequest { Target = entityReference, FileAttributeName = fieldNameOfFile, FileName = fileName, }; InitializeAnnotationBlocksUploadResponse initResponse = (InitializeAnnotationBlocksUploadResponse)service.Execute(initRequest); CommitFileBlocksUploadRequest commitRequest = new CommitFileBlocksUploadRequest { BlockList = blockList, MimeType = InfSystem.GetMimetypeByFilename(fileName), FileContinuationToken = initResponse.FileContinuationToken }; CommitFileBlocksUploadResponse comitResponse = (CommitFileBlocksUploadResponse)service.Execute(commitRequest); long fileSizeInBytes = comitResponse.FileSizeInBytes; return fileSizeInBytes; }

I have the same question (0)
  • Esteban Coto Alfaro Profile Picture
    on at

    Hello, to declare a BlockList you can do it in the following ways:

    For type string []:
        public string [] BlockList {get; set; }

    You can check it at the following link: https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.commitfileblocksuploadrequest.blocklist?view=dynamics-general-ce-9#Microsoft_Crm_Sdk_Messages_CommitistFilestlocklock_Messages_CommitistFilestlock_lockRequest

    For the string type:
        public string BlockId {get; set; }

    You can check it in the following link: https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.uploadblockrequest.blockid?view=dynamics-general-ce-9#Microsoft_Crm_Sdk_Messages_UploadBlockRequest_BlockIsages_UploadBlockRequest_BlockIsages_UploadBlockRequest_BlockIsages


    The complete information of the CommitFileBlocksUploadRequest Class can be found at the following link: https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.commitfileblocksuploadrequest?view=dynamics-general-ce-9

    Thanks!

    Community Support Team - Esteban
    If this Post helps, then please consider Accept as solution to help the other members find it more quickly.

  • RobertHaupt Profile Picture
    5 on at

    Hi Esteban,

    yes, BlockList is a string array but how can fill it with the bytes of an bytes array of the file?

    And how to enter code in a ticket to be shown in a goog readable way?

    Best Robert

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans