Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
private void button1_Click(object sender, EventArgs e)
       {
           DialogResult dr = openFileDialog1.ShowDialog();
           if (dr == DialogResult.OK)
           {
               string filename = openFileDialog1.FileName;
               int len= openFileDialog1.FileName.Length;
           }

       }



Here, i am getting the length of a file but, infact i want filebytes of a file in byte[]....to compare it with the database file which is stored in binary data (image data type).


plz help...:)
thanks in advance...:)
Posted
Comments
Bernhard Hiller 25-Mar-14 3:52am    
Note that
int len= openFileDialog1.FileName.Length
tells you the length of the FILENAME in characters!

Use File.ReadAllBytes():
C#
byte[] b = File.ReadAllBytes(filename);
 
Share this answer
 
Bitmap bmp = new Bitmap(image);
                FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
                byte[] bimage = new byte[fs.Length];


another way
 
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