Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other VB.NET Posts   Ask New Question  Ask New Question With Power Editor

converting a file to an array of bytes.
azy mohammadi posted at Saturday, November 07, 2009 5:16 AM

hi,how can I convert a file to an array of  bytes?

thanks 

Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
C# code you can translate
Robbe Morris replied to azy mohammadi on Saturday, November 07, 2009 9:02 AM

http://www.eggheadcafe.com/sample-code/csharp.NET/1a359260-03ad-474d-bfff-28f931d9b6d5/c-net-read-binary-file.aspx
Reply    Reply Using Power Editor
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0

re
Web star provided a rated reply to azy mohammadi on Saturday, November 07, 2009 10:53 AM

This function is used to convert file into byte array. some time we require to convert file into byte to save into database or send to other system using remoting.

 

private byte [] StreamFile(string filename)
{
    FileStream fs = new FileStream(filename, FileMode.Open,FileAccess.Read);

    // Create a byte array of file stream length
    byte[] ImageData = new byte[fs.Length];

    //Read block of bytes from stream into the byte array
    fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));

    //Close the File Stream
    fs.Close();
    return ImageData; //return the byte data
}

Reply    Reply Using Power Editor
  Rank Winnings Points
November 5 $56.00 138
October 10 $28.00 94

recieve the file?
azy mohammadi replied to Robbe Morris on Thursday, November 12, 2009 2:14 PM

hi,when I converted the file to an array of bytes ,and I sent it to another computer in my lan ,where this array of file will  save and how can I save it to a specific folder? 
Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0

Using the FileStream again
Robbe Morris replied to azy mohammadi on Thursday, November 12, 2009 2:39 PM

http://www.eggheadcafe.com/sample-code/csharp.NET/622b562f-3517-4ad6-af53-f0c4cb9dfad4/write-a-byte-to-a-binar.aspx

Reply    Reply Using Power Editor
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0