Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

i want to insert a doc file with base 64 encryption into sql 2008.

can any one please tell me the way.

Thanks,
balu
Posted

1 solution

Try:
C#
byte[] bytes = File.ReadAllBytes(@"D:\Temp\Myfile.doc");
string encode = Convert.ToBase64String(bytes);
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn) VALUES (@ENC)", con))
        {
        com.Parameters.AddWithValue("@ENC", System.Text.Encoding.ASCII.GetBytes(encode));
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900