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 :
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
    Microsoft Employee 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

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

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 123

#2
Hamza H Profile Picture

Hamza H 112 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans