1

I have a console application using C# where I want to read the blob stored in SQL Server and write it to windows file system at a specified path.

How do I convert a blob to a image of pdf using C# and write it to a file system?

4
  • @oded, I have no idea how to do it...never worked with blob... Commented Apr 28, 2011 at 19:13
  • possible duplicate of Retrieving image from sql database Commented Apr 28, 2011 at 19:13
  • Answers to this question for SQLite might help you: stackoverflow.com/questions/625029/… Also, entering "sql server c# blob read" in to Google returned loads of pages of info. Commented Apr 28, 2011 at 19:14
  • And here is another good question/asnwer from SO if you are dealing with large blobs: stackoverflow.com/questions/1487808/… Commented Apr 28, 2011 at 19:17

3 Answers 3

1

Read the blob from the database into a byte[] and write this buffer to a file.

Sign up to request clarification or add additional context in comments.

2 Comments

blob can be of any file type is it ? how to the program recognize that its an image file or pdf file ?
@Anuya - it can't and it doesn't. You need to tell it. In most cases, when saving a blob to a database, some additional data is saved with it to identify the type (unless all files are of the same type).
1

Take a look here: http://www.akadia.com/services/dotnet_read_write_blob.html

Using a DataAdapter / DataSet would most likely prove even easier - if you can afford to have the entire BLOB content loaded into memory for the number of rows you're processing.

Comments

0

What kind of blob are we talking about here? Assuming you are using .NET, Check out SqlDataReader or Entity Framework. There are other methods as well but those 2 are pretty popular. Converting to PDF you will probably need a 3rd party tool, check out PDF Sharp. Finally, saving to filesystem is pretty straightforward, look at the .NET System.IO.File class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.