hi,
can anyone help me,How can i convert the file to a byte array and then upload in to a server.
Thank you
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Jan 24, 2011, 5:43 AM
Krishna GaradPosted Jan 24, 2011, 4:56 AM
// For storing uploaded file on server
string virtualFolder = "~/Files/";
string physicalFolder = Server.MapPath(virtualFolder);
FileUpload1.SaveAs(physicalFolder + FileUpload1.FileName);
// Convert to byte array
Int32 intAudioSize = 0;
Stream AudioStream = null;
// Gets the Size of the File
intAudioSize = FileUpload1.PostedFile.ContentLength;
// Reads thefile
AudioStream = FileUpload1.PostedFile.InputStream;
byte[] AudioContent = new byte[intAudioSize + 1];
int intStatus = 0;
intStatus = AudioStream.Read(AudioContent, 0, intAudioSize);
BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream);
FileStream fstm = new FileStream(completeFileName, FileMode.Create, FileAccess.ReadWrite);
// writin file content on specified file
BinaryWriter bw = new BinaryWriter(fstm);
// Byte array for database insertion if you want
byte[] buffer = br.ReadBytes(FileUpload1.PostedFile.ContentLength);
br.Close();
bw.Write(AudioContent);
bw.Flush();
bw.Close();