google

Convert byte[] array into base64 string in C#.NET or ASP.NET

| Wednesday, April 2, 2014
Following is the code which can be used to convert an Image data from the SQL Server Database Image type column. SQL Server returns image column in the format of byte array i.e byte[].

  if (ds.Tables.Count > 0)  
       {  
         if (ds.Tables[0].Rows.Count > 0)  
         {  
           string MyImage = Convert.ToBase64String((byte[]) ds.Tables[0].Rows[0]["MySnap"]);  
          }  
       }  

We can retrieve the image column in DataSet or using the DataReader and then use Convert.ToBase64String() method to convert it into base64 string.

Above code can also be used for WCF service methods while sending data from database to mobile devices or some other purpose.

0 comments:

Post a Comment

Next Prev
▲Top▲