C # saves a binary string to a local

Source: Internet
Author: User
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)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.