locked
How to create a storangeFile from an array of bytes

    Question

  • Hi guys,

    I'm trying to share images using the charm bar, but I have the images as arrays of bytes in a DB. I'm following the example that uses a file picker to select the images and create the storangeFile. I don't need to use the file picker so I would like to know a way to create the storangeFile from an array of bytes.

    this is the code using the file

    if(this.imageFile != null)

                {

                

    //   StorageFile mySf = new StorageFile();


     

                   

    DataPackagerequestData = request.Data;

                    requestData.Properties.Title = TitleInputBox.Text;

                    requestData.Properties.Description = DescriptionInputBox.Text;

    // The description is optional.


                    requestData.Properties.ContentSourceApplicationLink = ApplicationLink;

     

                   

    // It's recommended to use both SetBitmap and SetStorageItems for sharing a single image


                   

    // since the target app may only support one or the other.


                   

    List<IStorageItem> imageItems = newList<IStorageItem>();

                    imageItems.Add(

    this.imageFile);

                  

                    requestData.SetStorageItems(imageItems);

                   

    RandomAccessStreamReferenceimageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);

                    requestData.Properties.Thumbnail = imageStreamRef;

                    requestData.SetBitmap(imageStreamRef);

                    succeeded =

    true;

                }

    Sunday, April 20, 2014 9:40 PM

Answers

  • Hi Santiago,

    Without the FileSavePicker, user cannot save the file to their own folder, take a look at the File access and permissions.

    However, you can always save a StorageFile as you wish, take a look: Quickstart: Reading and writing files

    In your scenario, you have a image which is byte[] array, you can use something like:

    await Windows.Storage.FileIO.WriteBufferAsync(sampleFile, buffer);
    

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, April 21, 2014 2:35 AM
    Moderator