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.             }
  17.  
  18.             return fileBytes;
  19.         }

Comments

public async Task :)

public async Task

:)

Thanks

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

error

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 rushanessay.com is helping the developers to make this code in a correct way.

https://www.emergencyessays.com/

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.

Yahoo

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?

Shweta
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.

GET MORE :- https://mailphonesupport.wordpress.com/2016/03/22/yahoo-mail-forgot-pass...

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.
Thanks
oren loni

good

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

games

Free gems for more coins. clashrealmer.com

Solutions

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

school

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. wholesaletabletcosts.com

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

Yahoo Support

If you are facing some technical problems with password in your Yahoo email account, then you can simply contact Yahoo mail customer service expert and rest assured that all technical trouble would be easily resolved in few second.

http://fontdebate-blog.logdown.com/

Many tutorials are available to let the people know about the storagefile.The methods of C# should be improved for the betterment of this

Useful info

Since I am a computer science students and have to done project based on C#, this piece of information is very useful to me. I have tried to execute the source code which you have provided here and it works successfully. Thank you. paris sightseeing tours

The return type of an async

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

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

Free Case studies

Hey. I am a professional writer of academic case studies and essays. Write me!
http://acasestudy.over-blog.com/2017/07/book-marketing-tips-for-maximum-...

tariq

I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!

Easily, the article is

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

tariq

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

I think you have provided a

I think you have provided a nice sharing through this article. I think sharing this kind of examples is really a help for students who are learning the computer programs. You have specified the simple method over here and i think it is good for recollecting the simple methods for students. pre manufactured home for sale

shahrukh

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.
vernacare products

Easily, the article is

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

I am always searching online

I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!

his is my first time i visit

his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

tariq

I feel a lot more people need to read this, very good info! . . . . . .

Yahoo Attachment Upload and Download

The Yahoo expert team run ahead of the users’ requirements, they already foreseen Yahoo Attachment Upload and Download and Spam Mails issue and they developed a solution too. You can use Yahoo Spam filter to keep spam mails away from your inbox. All you need to do is simply activate this Spam Filter and get rid of with this issue.

John Morin

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

The public is welcome to

The public is welcome to attend. For more information call (321) 433-7264. Johnson has written the books To Kill a Mockingbird: Threatening Boundaries and Understanding to Kill a Mockingbird: A Student Casebook. Diane Talluto's Reading Class at Brevard Community College will participate in the program throughout the month of February.

This insurance called

This insurance called California business insurance which is really a good plan for business insurance. When you have an insurance on your business, you will be protected against all the unexpected losses.

I would like to thank you for

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
chrome

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.