C # saves a binary string to a local
#region Save the file to local///<summary>///Save the file to local///</summary>//<param name= "p Scontent "> Binary data string for file </param>//<param name=" psfilename "> file name, must have suffix </param> private v OID SaveFile (String pscontent, String psfilename) {byte[] accessory = convert.frombase64string (Psconten T); System.AppDomain.CurrentDomain.BaseDirectory gets the base directory of the program string vsaccessorypath = System.AppDomain.CurrentDomain. Basedirectory.trimend (' \ \ ') + ' \ \ ' + psfilename; FileStream FileStream = null; try {//file.create Method (String): Creates or overwrites a File in the specified path. FileStream = File.create (Vsaccessorypath); } catch (System.IO.IOException e) {}//filestream.write Metho D:writes a block of bytes to the file stream. FileStream.Write (accessory, 0, accEssory. Length); Filestream.flush method: Clears all buffers for the stream so that all buffered data is written to the underlying device. Filestream.flush (); Filestream.close method:closes the file and releases any resources associated with the current file stream. Filestream.close (); } #endregion
If the file stream is stored in the database:
String vssql = "";//Gets the contents of the saved file to be converted from the database (for example, before converting the file to a byte stream saved to the database) DataSet dscontent = Gets the database operation of the dataset; byte[] Vbcontent = ( Byte[]) (Dscontent.tables[0]. rows[0]["The column name of the file contents in the database"]); string vsContent = Convert.tobase64string (vbcontent);
What the byte stream looks like in the database:
The above is C # to save the binary string to local content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!