This Function converts a file To bytes And returns it
CODE:
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;
}
}
0 comments:
Post a Comment