HomeBlogLarge File Storage in Dynamics CRM Attachments
Large File Storage - Blog about Microsoft technologies

Calendar iconPublished:

Time iconTime to read:5 min

Large File Storage in Dynamics CRM Attachments

Dynamics 365
Data management
Solution

A Short Overview of the Article

In this article, we will explore a practical solution to overcome this limitation by splitting large files into smaller parts, storing them as separate attachments, and combining them when needed. We will also cover how to configure attachment size limits and implement file-splitting and reconstruction functionality using C#.

A Short Reference about the Author

Mykhailo is an experienced Dynamics 365 Developer with extensive hands-on expertise in Dynamics 365, the Power Platform, and Azure, specializing in developing and customizing Dynamics 365 CRM solutions.

Introduction

Managing large files in Microsoft Dynamics 365 CRM can be challenging due to the platform's default attachment size limit and Dataverse file storage restrictions. Companies frequently need to upload documents, media files, archives, and integration of payloads that exceed the maximum supported attachment size. As a result, implementing a reliable large file storage strategy in Dynamics 365 becomes essential.

Dynamics 365, Dataverse, and File Storage Considerations

Since Dynamics 365 applications are built on Microsoft Dataverse, understanding the available storage mechanisms is important. Dataverse supports attachments, file columns, image columns, notes (annotations), and integrations with external storage platforms. However, each storage option has different file size limitations, performance characteristics, and licensing implications.

Therefore, selecting the appropriate Dataverse file storage strategy is an important architectural decision.

Changing File Size Limits for Attachments

The Dynamics 365 system administrator can change the maximum size of attachments from 0 to 128 MB (131,072 KB) in the System Settings dialog box.

The implementation steps:

  1. Click on the "Gear Icon" at the top --> Select the "Advance Settings".

  2. It will open the "Settings" page --> Select the "Administration".

    Large File Storage in Dynamics CRM Attachments - Change File Size Limit for Attachments
  3. Press the "System Settings".

    Large File Storage in Dynamics CRM Attachments - System Settings
  4. Once the page is loaded, select the "Email" tab.

    Large File Storage in Dynamics CRM Attachments - System Settings

! Note. Here, you will find the section called "Set file size limit for attachments," where you can set the maximum attachment file size in kilobytes. The default size limit for attachments is 5120kB/5MB but can be increased to 32768Kb/32MB for older versions of CRM and 131072Kb/128MB for newer versions of CRM.

Now, let us explore the maximum size the system can allow.

Large File Storage in Dynamics CRM Attachments - System Settings

! Note. Within the Dataverse Environment, only values ranging from 0 to 131,072 are permitted.

Splitting Files into Multiple Parts

Unfortunately, 128 MB (131,072 KB) is insufficient. Consequently, we can overcome this limitation by dividing our file into smaller parts. This process is straightforward and is a common workaround for larger files.

To divide a file into parts, you can use the following code:

Code
static List<byte[]> DivideFile(byte[] data, int chunkSize){    List<byte[]> fileParts = new List<byte[]>();     int offset = 0;    while (offset < data.Length)    {        int remaining = data.Length - offset;        int bufferSize = Math.Min(chunkSize, remaining);         byte[] buffer = new byte[bufferSize];        Buffer.BlockCopy(data, offset, buffer, 0, bufferSize);         fileParts.Add(buffer);        offset += bufferSize;    }    return fileParts;}

! Note. When specifying the 'chunkSize' as the part size limit in bytes, it should be set to a value lower than the attachments limit.

You can verify this using the following code:

Code
public int GetAttachmentSizeLimit()        {             QueryExpression query = new QueryExpression("organization")            {                ColumnSet = new ColumnSet("maxuploadfilesize")            };             return Service.RetrieveMultiple(query).Entities                .FirstOrDefault().GetAttributeValue<int>("maxuploadfilesize");        }

Now, you have to save a portion of the data in separate attachments and associate the relevant information.

The following details are required:

File information:

Name

Type

Description

FileId

Guid

File identifier

FileTotalParts

int

Total number of parts

Parts information:

Name

Type

Description

FilePartId

Guid

File part identifier

FilePartNumber

int

Part sequence number

! Note. Each section should be assigned a sequence number, FilePartNumber, ranging from 0 to the specified value of the corresponding configuration parameter minus 1.

Code
public class FileInfo{    public Guid FileId { get; set; }    public int FileTotalParts { get; set; }    public List<FilePartInfo> FileParts { get; set; }} public class FilePartInfo{    public Guid FilePartId { get; set; }    public int FilePartNumber { get; set; }}

The example of creating annotations:

Code
List<byte[]> fileParts = DivideFile(data, chunkSize); Entity fileInfoRecord = new Entity("FileInfoEntity");fileInfoRecord.Id = _service.Create(fileInfoRecord); FileInfo fileInfo = new FileInfo(){    FileId = fileInfoRecord.Id,    FileTotalParts = fileParts.Count,    FileParts = new List<FilePartInfo>()}; for (int i = 0; i < fileParts.Count; i++){    Entity filePartRecord = new Entity("annotation")    {        Attributes =        {            { "documentbody", Convert.ToBase64String(fileParts[i]) },            { "subject", "File subject" },            { "filename", $"FileName_part{i}.bin" },            { "objectid", fileInfoRecord.ToEntityReference() },        }    };     filePartRecord.Id = _service.Create(filePartRecord);     fileInfo.FileParts.Add(        new FilePartInfo() { FilePartId = filePartRecord.Id, FilePartNumber = i }    );} fileInfoRecord["JSON"] = JsonConvert.SerializeObject(fileInfo);_service.Update(fileInfoRecord);

Joining Split Files

To join a file from parts, you can utilize the following code:

Code
static byte[] JoinFiles(List<byte[]> fileParts){    int totalSize = fileParts.Sum(part => part.Length);    byte[] joinedData = new byte[totalSize];     int offset = 0;    foreach (byte[] partData in fileParts)    {        Buffer.BlockCopy(partData, 0, joinedData, offset, partData.Length);        offset += partData.Length;    }    return joinedData;}

The example of joining file parts:

Code
Entity fileInfoRecord = _service.Retrieve("FileInfoEntity", fileId, new ColumnSet(true));FileInfo fileInfo = JsonConvert.DeserializeObject<FileInfo>(    fileInfoRecord.GetAttributeValue<string>("JSON")); QueryExpression query = new QueryExpression("annotation"){    ColumnSet = new ColumnSet(true),    Criteria =    {        Conditions =        {            new ConditionExpression("objectid", ConditionOperator.Equal, fileInfoRecord.Id)        }    }}; DataCollection<Entity> fileParts = _service.RetrieveMultiple(query).Entities; List<byte[]> sorteredFileParts = new List<byte[]>(); for (int i = 0; i < fileInfo.FileTotalParts; i++){    sorteredFileParts.Add(        Convert.FromBase64String(            fileParts                .First(x => x.Id == fileInfo.FileParts.First(y => y.FilePartNumber == i).FilePartId)                .GetAliasedValue<string>("documentbody")        )    );} byte[] fileData = JoinFiles(sorteredFileParts);

Why Dynamics 365 Attachment Limits Matter

Understanding the Dynamics 365 attachment size limit is critical when designing document management solutions. Although administrators can increase the maximum attachment size to 128 MB, companies that process contracts, engineering documents, multimedia files, or data exports may still exceed this threshold.

In such scenarios, alternative approaches such as file chunking, external storage, or Azure-based integrations should be considered.

Best Practices for Large File Storage in Dynamics 365

When implementing a large-file solution in Dynamics 365 CRM, consider the following best practices:

  • Keep chunk sizes below the configured attachment limit

  • Validate file integrity during reconstruction

  • Implement retry mechanisms for failed uploads

  • Detect missing or duplicate file parts

  • Store metadata separately from file content

  • Explore Azure Blob Storage for files that significantly exceed Dynamics 365 limits

  • Monitor Dataverse storage consumption to avoid unexpected capacity issues

Conclusion

Managing files that exceed the Dynamics 365 attachment size limit can be challenging, particularly for organizations that rely heavily on document-intensive business processes. By implementing a file chunking strategy that splits large files into smaller parts and reconstructs them when required, administrators and developers can effectively overcome standard Dynamics 365 CRM attachment limitations.

In addition, understanding how Dataverse file storage, annotations, and attachment settings work enables companies to design more scalable solutions. For extremely large files, integrating Azure Blob Storage with Dynamics 365 may provide an even more efficient long-term storage strategy.

The approach described in this article provides a practical and reliable method for storing large files in Dynamics 365, while maintaining compatibility with the platform's native attachment functionality.

Frequently Asked Questions

Share