VB.NET - converting a file to an array of bytes.

Asked By azy mohammadi
07-Nov-09 05:16 AM

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

thanks 

re  re

07-Nov-09 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 http://www.dotnetspark.com/kb/3-convert-file-into-byte-array.aspx# 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
}

recieve the file?  recieve the file?

12-Nov-09 02: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? 
Create New Account
help
to Byte Array string filePath = Server.MapPath( "APP_DATA / TestDoc.docx" ); string filename = Path .GetFileName(filePath); FileStream fs = new FileStream (filePath, FileMode .Open, FileAccess .Read); BinaryReader br = new BinaryReader (fs); Byte [] bytes = br.ReadBytes(( Int32 )fs.Length); br.Close(); fs.Close(); VB.Net ' Read the file and convert it to Byte Array Dim filePath As String = Server.MapPath APP_DATA / Testxls.xlsx" ) Dim filename As String = Path.GetFileName(filePath) Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read) Dim br As BinaryReader = New BinaryReader(fs) Dim
mean by xml buffer? hi, To work with a local disk file, you use the FileStream class, which lets you move data to and from the stream as arrays of bytes. To make it easier to read and write basic data types, you can use the the equivalent methods of the StreamReader and StreamWriter classes. All these classes wrap an underlying FileStream and provide methods that make it easier to read and write data in the appropriate You can store numbers either as text (in XML format), or in their native format. VB.NET supports traditional random access files, but it doesn't really need them. You can still which class you decide to use to access a file, you must first create a FileStream object. There are several ways to do that. The simplest method is to specify the file and how it will be opened in the FileStream object's constructor, which has the following syntax: Dim fStream As New FileStream(path, _ fileMode, fileAccess) The path argument contains the full pathname of the file you
password for the VB.Net published setup file Could any1 tell me how could i keep password for the VB.Net published setup file. That would ask before setup the installation. My Lockbox™ is a security As String Dim strOutputEncrypt As String Dim strOutputDecrypt As String Dim fsInput As System.IO.FileStream Dim fsOutput As System.IO.FileStream Creating the Key Of course, the most secure Key would be a randomly generated Key Define the enumeration for CryptoAction (encrypt / decrypt). Begin with an encrypted / unencrypted file. Use a FileStream object to open and read the file. Use a CryptoStream object to perform encryption / decryption. Use another FileStream object to write the encrypted / decrypted file. For a more in-depth description read the
Zipping folder in VB.NET how to zip a folder programetically in vb.net Adapt code in this article - http: / / www.eggheadcafe.com / tutorials / aspnet / 9ce6c242-c14c-4969-9251-af95e4cf320f / zip- -unzip-folders-and-f.aspx To convert C# code to VB.NET, use one of these converters - http: / / www.carlosag.net / Tools / CodeTranslator / http: / / labs.developerfusion.co As Stream, buffer() As Byte) As Integer ' Use this method is used to read all bytes from a stream. Dim offset As Integer = 0 Dim totalCount As Integer = 0 While True method to compare data from two different buffers. If len1 <> len2 Then msg = "Number of bytes in two buffer are different" & len1 & ":" & len2 MsgBox(msg) Return False End If Dim i
Metadata VB.NET How to save Image With Metadata using vb.net or c# CreateInPlaceBitmapMetadataWriter (1) InPlaceBitmapMetadataWriter (1) BitmapCreateOptions (1) BitmapCacheOption (1) PngBitmapDecoder (1) SetPropertyItem (1) ConstructorInfo (1) ImageMetadata (1) This is sample code for this- Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open FileAccess.ReadWrite, FileShare.ReadWrite); PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapFrame pngFrame = pngDecoder Class clsReadMetaData Public Function ReadEXIFMetadata(ByVal filepath As String) As ImageMetadata Dim fs As New FileStream(filepath, FileMode.Open, FileAccess.Read) Dim image_ _1 As Image = Image.FromStream(fs) Dim imagePropertyItems As