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; }

  • RobertHaupt Profile Picture
    5 on at
    RE: Upload File to CRM File-Field with C#

    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

  • Esteban Coto Alfaro Profile Picture
    on at
    RE: Upload File to CRM File-Field with C#

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 72

Overall leaderboard

Product updates

Dynamics 365 release plans