Using system;using system.io;using system.web;using system.web.ui.webcontrols;namespace DotNet.Utilities{//< summary>///File Upload class///</summary> public class Fileup {public Fileup () {}// <summary>//Convert to byte array///</summary>/<param name= "filename" > file name </param> <returns> byte array </returns> public byte[] Getbinaryfile (string filename) {if ( File.exists (filename)) {FileStream Fsm = null; try {Fsm = file.openread (filename); return this. Convertstreamtobytebuffer (FSM); } catch {return new byte[0]; } finally {fsm.close (); }} else {return new byte[0]; } }///<summary>///flow into byte array///</summary>//<param name= "Thestream" > Stream </param>//<returns> byte array </returns> public byte[] Convertstreamtobytebuffer (System.IO.Str EAM thestream) {int bi; MemoryStream tempstream = new System.IO.MemoryStream (); try {while (bi = Thestream.readbyte ())! =-1) {TEMPSTREAM.W Ritebyte (((byte) bi)); } return Tempstream.toarray (); } catch {return new byte[0]; } finally {tempstream.close (); }}///<summary>//Upload file///</summary>//<param name= "Posphotouploa D "> Controls </param>//<param name=" Savefilename "> Saved filenames </param>///<param name=" Imagepa Th "> Saved file path </param> public string Filesc (FileUpload posphotoupload, String savefilename, String imagePath) { string state = ""; if (posphotoupload.hasfile) {if (posphotoupload.postedfile.contentlength/1024 < 10240) {string MimeType = PosPhotoUpload.PostedFile.ContentType; if (String.Equals (MimeType, "Image/gif") | | String.Equals (MimeType, "Image/pjpeg")) {string extfilestring = System.IO.Path. GetExtension (PosPhotoUpload.PostedFile.FileName); PosPhotoUpload.PostedFile.SaveAs (HttpContext.Current.Server.MapPath (ImagePath)); } else {state = "Incorrect upload file type"; }} else {state = "Upload file cannot be greater than 10M"; }} else { state = "File not uploaded"; } return state; }///<summary>//Upload file///</summary>//<param name= "Bindata" > byte array </p aram>//<param name= "filename" > FileName </param>//<param name= "fileType" > File type </param& Gt -------------------call----------------------//byte[] by = Getbinaryfile ("E:\\hello.txt"); This. SaveFile (By, "Hello", ". txt"); ---------------------------------------------public void SaveFile (byte[] bindata, String fileName, String filety PE) {FileStream FileStream = null; MemoryStream m = new MemoryStream (bindata); try {string savepath = HttpContext.Current.Server.MapPath ("~/file/"); if (! Directory.Exists (Savepath)) {directory.createdirectory (Savepath); } string File = Savepath + fileName + FileType; FileStream = new FileStream (File, FileMode.Create); M.writeto (FileStream); } finally {m.close (); Filestream.close (); } } }}