hi,
can anyone help me,How can i convert the file to a byte array and then upload in to a server.
Thank you
File uploading
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Jan 23, 2011, 11:56 PM EST
// 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();
Suthish NairRank #92 · 22.8K reputationPosted Jan 24, 2011, 12:43 AM EST