How C # saves binary strings to local

Source: Internet
Author: User
#region save files to local///<summary>///save files to local///</summary>///<param name= "pscontent" > File binary Data  String </param>///<param name= "psfilename" > file name, must be with suffix </param> private void savefile (String pscontent,  
    String psfilename) {byte[] accessory = convert.frombase64string (pscontent); System.AppDomain.CurrentDomain.BaseDirectory the base directory string Vsaccessorypath of the FETCH program =
    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 method:writes a block of B  
    Ytes 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 of the associated with the" current file stream.  
Filestream.close (); } #endregion

This paper url:http://www.bianceng.cn/programming/csharp/201410/45587.htm

If the file stream is saved in the database:

String vssql = ""; Get the contents of the saved file to be converted from the database (for example, convert the file to a byte stream before saving it to the database)

DataSet dscontent = database operation to obtain dataset;

Byte[] Vbcontent = (byte[]) (dscontent.tables[0). rows[0]["column name for saving file contents in database"]);

String vsContent = Convert.tobase64string (vbcontent);

The way a byte stream is saved in a database:

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.