Skip to main content

Reading a StorageFile to a byte array in C#

Reading a StorageFile to a byte[] or an IRandomAccessStream in a Windows 8 app wasn't exactly obvious and the examples I found included other classes or unnecessary processing. I created this solution based upon what I learned and wanted to share it...

  1.         /// <summary>
  2.         /// Loads the byte data from a StorageFile
  3.         /// </summary>
  4.         /// <param name="file">The file to read</param>
  5.         public async Task<byte[]> ReadFile(StorageFile file)
  6.         {
  7.             byte[] fileBytes = null;
  8.             using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
  9.             {
  10.                 fileBytes = new byte[stream.Size];
  11.                 using (DataReader reader = new DataReader(stream))
  12.                 {
  13.                     await reader.LoadAsync((uint)stream.Size);
  14.                     reader.ReadBytes(fileBytes);
  15.                 }
  16.             }
  18.             return fileBytes;
  19.         }


public async Task :)

public async Task



Thanks and you're right. I will update the post.


The return type of an async method must be void, Task or Task

The perfection of making this

The perfection of making this code is so important to get the desired project just in time.There are many methods for making the proper way of preparing the project.This is helping the developers to make this code in a correct way.

Totally, the actual write-up is really the very best in that will worthwhile matter. I really fit in jointly with your results and certainly am going to keenly seem to be toward your own upcoming improvements. Just telling many thanks could not only be sufficient, for your exceptional readability as part of your composing.I'll use this information to provide term papers for my friends.


Get answers to your Yahoo technical support questions. Here's how to find
Yahoo Customer Service options at Yahoo Help Central.

Many tutorials are available

Many tutorials are available to let the people know about the storagefile.The methods of C# should be improved for the betterment of this custom writing help which is essential to write an appropriate assignment,

These are really a superb

These are really a superb showcases here I am glad to have a review of it and feel to roll on its steps for my benefit always
Engineering college in Chandigarh
Engineering college in punjab

Year 2013 has been quite

Year 2013 has been quite eventful. SRSG also witnessed events and evolved in terms of business verticals, technologies, people and processes.
Apple service center Mumbai
Audio mixer dealers

reading the binary file in windows storage

How can I read a binary file in a Windows Store app, or more specifically how can I create my Stream, when the System.IO namespace contains no File class?

Web Designer and .Net Web Developer

Yahoo Customer Service Number 24/7

There are many troubles that you can face while you are working with the yahoo account and in case you are facing trouble with password, then you can rest assured that the trouble would be easily solved in minutes at most since the solution to this particular trouble is very readily available.


Yahoo Forgot Password Recovery

Facing trouble with the email account is not a very uncommon issue. Technical issue can crop up from time to time since no technology is ideal. However, when you have the account with the yahoo mail, one can rest assured that the solutions would be provided with much care and very professionally.

Yahoo is one of the leading service providers on the interne

Yahoo is one of the leading service providers on the internet. The service provider exists before Yahoo came into the scenario, and many people have their e-mail accounts with Yahoo. To get the full benefit of the applications provided by Yahoo, one needs to sign-up with their name, address and phone number and other details.

Yahoo Phone Number for Shortest wait or best Customer Service

There can be several types of problems related to Yahoo mail account but one of the most common problems is the issue of temporary errors. One may not understand why they’re facing temporary errors so often. The problem can be taken care of easily by taking a few simple steps.

Experienced Technical Service for Yahoo Mail

Data transmission on the internet is never 100% safe. Despite the efforts made by you to protect yourself from data breaching and malicious activities of the internet, you have to suffer a lot. However, you have also made possible efforts to optimize the security of data.

We are needed these essays

We are needed these essays for reading assignmentmasters strong file byte array. That all prepared to gather your great steps and sources. Then everything will be good to understood your values.

Thanks for sharing the code

Thanks for sharing the code to reading a StorageFile to a byte array in C#. I am doing BCA and we are handling C# now. Your tips and suggestions about coding is very helpful for me to practice this programs and execute them. Thanks for your help.
oren loni


Dealing with these C programming codes and especially the arrays has been a very confusing task for me since the school days. This one looks quite simpler than the usual lengthy codes and will be helpful for the readers to get a better understanding of the topic. same day dry cleaning Malibu


Free gems for more coins.


Solutions Middle East, works to Envision, Execute and Empower our clients by offerings design, implementation and on-going support services.
Nutanix Premier Partner
Citrix Platinum Partner
VDI in a box
Staff Outsourcing
SMS Gateway providers
Citrix Mobility Solutions


DPS has a very good hostel for the students where they get homely environment. Students of various age groups and different places live in the hostel. They get opportunity to interact with diverse group of students and people. In hostel students develop their confidence and become independent.
Best School in rajasthan

VIGYAN DHARA is the first

VIGYAN DHARA is the first Indian IIT-JEE/ NEET/AIIMS coaching Institute which is purely based on Historical Indian Education System that is the Gurukul Tradition of Education where students leave their homes during their studies.
PMT coaching institute in hisar
IIT Coaching center in hisar<

Moonlight Films and Theatre

Moonlight Films and Theatre Studio operates under the Moonlight Films and Theatre Society , a non-profit association whose goals are to spread knowledge of and interest in theatrical and media arts through education.
Filmmaking classes in Delhi
Acting school in Delhi
Diploma in filmmaking in Delhi

SCS is focused on providing

SCS is focused on providing the most comprehensive, heterogeneous, integrated IT Software solutions to enterprises around the world.
Citrix Mobility Solutions
SMS Alert Solutions
Two way SMS Gateway provider
SysTrack for VDI
FOIP Connection

This is the first time I have

This is the first time I have come across this site and understand that this site was very much useful for students who are dealing with programming field. I really liked the simple structure of program you have shared here. Keep up the good work.

Nice Article

Thanks for sharing the code here. Your article on Reading a StorageFile to a byte array in C was really helpful in understanding the concept of accessing files in C. Do share more informative posts like this. It will be a great help to students and professionals alike. Join Army

Gmail Customer Care Expert

If you are unable to update profile picture and account information also looking for online technical help in your Gmail account, then you can contact our Gmail customer service 1800 toll free number 24*7 hours.

Take One School of Mass

Take One School of Mass Communication considered as a part of the Top Mass Communication Colleges in India. It was set up in the year 2003 by honing media experts who met with a mutual vision of giving a stage to the adolescent of the nation.
Top mass communication colleges in Delhi
Journalism courses in Delhi

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <asp>, <c>, <cpp>, <cs>, <css>, <drupal5>, <drupal6>, <html4strict>, <java>, <javascript>, <jquery>, <php>, <python>, <ruby>, <sql>, <xml>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.