Click here to Skip to main content
15,446,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using WPF application and using c++ dll in that from c++ dll i will read the file and send the memory to WPF application Eg:-files like excel, pdf, word. how to view those files through memory. need to view through the memory only not to write in a file and then open, any idea's or suggestion i will follow

What I have tried:

public void updateImage()
{
imagearray // The memory which i get from c++
SlectedImage.Source = LoadImage(imagearray);//set the source Image to the Image controll
}



 public static BitmapImage LoadImage(byte[] imageData)
        {
            if (imageData == null || imageData.Length == 0) return null;
            var image = new BitmapImage();

           
                using (var mem = new MemoryStream(imageData))
                {
                    mem.Position = 0;
                    image.BeginInit();
                    image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                    image.CacheOption = BitmapCacheOption.OnLoad;
                    image.UriSource = null;
                    image.StreamSource = mem;
                    image.EndInit();

                }


                image.Freeze();
return image

}



this code will work for image as same how to achieve for the documents to view in wpf application thorugh memory.
Posted
Updated 8-Jul-21 3:50am

1 solution

It depends on how you're planning on rendering these documents. If you mean to render them within your WPF application then you're going to need some embeddable controls, which I would assume take a Stream reference to load the content.

However if you're thinking about opening Excel from a byte array in memory and having it load it as though it's a file on the local file system: that's not possible. Instead you should consider saving the content to a temporary file and then open that file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900