0

i have HTML page source of website saved as String in string PageSource; i need to save it in SQL Database as Image of type image. How to convert PageSource in byte[] and save it as Image in database.

4
  • Are you trying to save an image of the rendered page to the database? Commented Mar 23, 2011 at 16:03
  • Do you want to make a picture of the website and save this picture or do you want to save the site's bytes in a in a picture field? Commented Mar 23, 2011 at 16:03
  • This is a hard problem if you are trying to parse the HTML and turn it into an image. Most of the browsers do it, so you could look into using the renderer parts of Webkit or Firefox. Commented Mar 23, 2011 at 16:05
  • I assume the OP is talking about the image datatype not creating pictures. You should use varbinary(max) as image is deprecated. Commented Mar 23, 2011 at 16:07

1 Answer 1

7

You can use the following code to convert a string to a byte array, which can then be saved in a database image field.

var bytes = Encoding.Default.GetBytes(htmlString);

Use of image will be deprecated, consider using varbinary(max).

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

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.