i have an issue when i am trying to convert a file into byte array using this code
var fileByte = new byte[pic.ContentLength];
it converts the file but when file is uploaded it is corrupted. and when i tried the another code to convert the file i.e
var pic = System.Web.HttpContext.Current.Request.Files["ImagePath"];
byte[] bytes = System.IO.File.ReadAllBytes(pic.FileName);
it thrown an exception like
Could not find file 'C:\Program Files\IIS Express\slide2.jpg'.
after words i'd tried for this
byte[] b = StreamFile(pic.FileName);
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
}
but it also throw and exception like
Could not find file 'C:\Program Files\IIS Express\slide2.jpg'.
System.IO.File.Exists(pic.FileName);if you file is available.