Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Friday, April 24, 2009

Converting blob data into a word file C#.NET

Byte[] bytData =null;

//Change the ConnString as per your system.

string constring = @"Data Source=LOCAL;Initial Catalog=DA;Integrated Security=True;"; SqlCommand command = new SqlCommand(@"SELECT BlobData FROM Lib.LibBlob WHERE BlobID='04F24251-AE4C-4FDA-BDB7-0689C9616462'"); command.CommandType = CommandType.Text;

SqlConnection myconn = new SqlConnection(constring);

command.Connection = myconn;


SqlDataReader dr = command.ExecuteReader();



bytData = (byte[])dr["BlobData"];


if (bytData !=null)


/*If it is a file other than imagetype change the extension in the filepath accordingly. */ FileStream fs = new FileStream("C:\\Temp\\Test1.doc", FileMode.OpenOrCreate, FileAccess.Write);
      BinaryWriter br = new BinaryWriter(fs);


Post a Comment

Anonymous said...

thanks for the post.