.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get stream of a file

Posted By:Amit Mehra       Posted Date: October 15, 2009    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  

Below code in form of function can be used to to get the stream of a file stored in hard drive. Code example is in C# and VB.Net.

C# code sample


/// This code sample to return stream ( Byte Array ) from a file stored in hard drive

/// File path as string
/// array of Byte
private byte[] StreamFile(string filename)

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

byte[] myFile = new byte[fs.Length];


return myFile;



In Vb.Net function

Private Function StreamFile(ByVal filename As String) As Byte()

Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)

Dim myFile As Byte() = New Byte(fs.Length) {}

fs.Read(myFile, 0, System.Convert.ToInt32(fs.Length))


Return myFile

End Function


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend