Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

Code To convert a file To bytes

This Function converts a file To bytes And returns it


public static byte[] GetByteFromPostedFile(System.Web.HttpPostedFile PostedFileToUpload)
{
if ((PostedFileToUpload != null))
{
// Instantiate new byte for referencing in Add/Update method
byte[] byteFile = null;

try
{
//// Get reference to newly posted file
//postedFile = uploadedFile.PostedFile;
// Get size of Uploaded file
int intContentLength = PostedFileToUpload.ContentLength;
// Allocate a buffer for reading of the file
byteFile = new byte[intContentLength];
// Read uploaded file from the Stream
PostedFileToUpload.InputStream.Read(byteFile, 0, intContentLength);

return byteFile;
}
catch
{
return null;
}
}
else
{
return null;
}
}

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy