DavidGreenberg
Crownpeak Employee

How To Read a Binary File In The CMS

I was wondering how do you read a binary file (i.e. an excel file, text file, ect) from within a template. Either through an attached or uploaded asset.

--


David Greenberg
Customer Support Engineer

## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..

0 Kudos
1 Reply
DavidGreenberg
Crownpeak Employee

To read an uploaded asset you will need to use the following code:

Read an asset uploaded into the CMS

System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(BinaryFile.LoadAsBase64(xmlAsset.Id.ToString())))

 Read an asset attached to an asset

System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(BinaryFile.LoadAsBase64(asset["attachedFileFieldName"])))

--


David Greenberg
Customer Support Engineer

## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..

0 Kudos