Blazor Server App load document from byte array

Hi
I was looking for a code example of loading a document from a byte array?

Thanks, Colin

@colin.wright,

You can use the overload;

var bytes = File.ReadAllBytes(filePath);
string extension = ".DOC";
var viewToken = ctlDoc.OpenDocument(bytes, extension, config);

Keep in mind that you can use a stream as well. Currently, there is a bug for PDF files using bytes[] or stream, which should be solved in the next release.

The workaround is to serialize it into a file and load it like that. Sadly, this will affect performance but will allow you to continue work for now.

If you can provide the FileInfo along with the byte[] you can use something like this:

byte[] file = File.ReadAllBytes(filePath);
Stream stream = new MemoryStream(file);
FileInfo fi = new FileInfo(filePath);
var viewToken = ctlDoc.OpenDocument(stream, fi);

This is for the sake of testing the functionality. You do not need the initial conversion. But providing the stream or bytes and the fileInfo will work.

Hi Carlos,

Thanks for the update, I was able to retreive my byte array from a controller endpoint and pass to the open document method, I am using a docx, but the document doesnt seem to display at all, with no errors. I can confirm my controller endpoint sucessfully downloads the document in the browser. I am using .net7 for my blazor app, which i know isn’t fully supported, but i can open the demo project and get it to run in .net7 and open the local files in the doconut viewer.

@colin.wright,

I see. I know the product will be updated, but the next one will be .NET 6, not 7. But maybe when that is done, it will work on NET 7, too.

Also, is your APP POOL for that website on Integrated mode?

Thanks, is there an ETA for the next version? I can work around and write the documents to temp folder then open them with the Jsinstance method.

@colin.wright,

I am so sorry, I am going to correct myself. I do not have access to the development releases. So I cannot claim what is going to be included or not in the next release.

I know that they are working on a version build natively on .NET 6. But on what version will be released, I cannot say. Sorry if I give you the wrong idea.

But I know that feature exists and that they are working on it. But on which version will be released I do not know.