Powered By Blogger

Thursday, November 12, 2009

Convert a file into bytes C#

private void GetOpenFileDialog()
{
openFileDialogX.CheckPathExists = true;
openFileDialogX.Filter = "Text files (*.text)|*.txt|doc files (*.doc)|*.doc|pdf files (*.pdf)|*.pdf|excel files(*.xls)|*.xls|excel files07(*.xlsx)|*.xlsx";
openFileDialogX.Multiselect = false;
openFileDialogX.AddExtension = true;
openFileDialogX.ValidateNames = true;
openFileDialogX.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialogX.ShowDialog();


Fname = openFileDialogX.FileName.ToString();
Fsize = openFileDialogX.FileName.Length;
Fext = System.IO.Path.GetExtension(Fname);



FileInfo fi= new FileInfo(Fname);
long numbyt= fi.Length;

FileStream FS = new FileStream(Fname, FileMode.Open, FileAccess.Read);
BinaryReader BR = new BinaryReader(FS);
filbyt = BR.ReadBytes(Convert.ToInt32(numbyt));




}




source: http://www.dotnetspider.com/projects/512-Store-Retrieve-pdf-txt-doc-Images-Sql-server-database.aspx

No comments:

Post a Comment