sql server 2005 - Want to read file retrieved from database in the same format it was being saved in C# windowsForm -
i using c# windows form application insert document file (word, pdf & text) in sql server database,the below code used convert file binary , after ward upload file in database:
fileinfo fileinfo = new fileinfo(file); string filename = system.io.path.getfilenamewithoutextension(file); string extension = system.io.path.getextension(file); long bytesize = fileinfo.length; filestream myfilestreams = new filestream(file, filemode.open, fileaccess.read); binaryreader br = new binaryreader(myfilestreams); byte[] filestream = br.readbytes((int)bytesize); the file saved when retrive database file not in readable format below code used retrieve database , save on local disk:
//the file fetch id , saved in datatable dt1 on row[0][1] byte[] cv = (byte[])dt1.rows[0][1]; string cvname = dt1.rows[0][0].tostring(); string ext = dt1.rows[0][2].tostring(); //saved in bin string pathofcv = "new\\" + cvname + ext; file.writeallbytes(pathofcv, cv); file.create(pathofcv); the retrieved file has unreadable text want read in same format saved , think there problem in conversion of file may can not directly write bytes array in file.
please give me code example how can resolve problem thanks.
maybe should try using memorystream smth like:
memorystream ms = new memorystream(cv); filestream file = new filestream(cvname + ext, filemode.create,system.io.fileaccess.write); byte[] bytes = new byte[ms.length]; ms.read(bytes, 0, (int)ms.length); file.write(bytes, 0, bytes.length); file.close(); ms.close();
Comments
Post a Comment