Monday, July 18, 2011

Store files in database

Scenario:


This may not be very common scenario but needed some time to store the files in database. Mostly the attachments needs to be stored in a database instead of maintaining as files.

Solution:

This is very easy with the .NET and SQL Sever environment. Let me start from the database side.We need to have the varbinary field in the database table in order to store the file stream. Look at the below image shows about the table structure.



We can go for the coding part, we'll use File upload control to get the file from the user. We need to convert the file stream in file upload control to byte array. This byte array has to be passed to the database as param.
Look at the screenshot of the code used to store the file,

Hope the above screenshot is explanatory about the code used. I would like to show how this parameter has been handled in executing the stored procedure.


Conclusion:


I believe the above code will be used to store the files in database.

Happy .NETting..

Thursday, July 14, 2011

MailMessage - Allowing html tags inside body text

Problem


This is the very simple scenario required when sending email from our application. We need to put html tags in the body of the text which we are sending.


We are expected to send the email with the above body. This should be appear in their inbox with two lines. The text "Dear Murugesan," should come in the first line and the rest in second line.

Solution

Normally this won't appear as we wish. We need to true the property named "IsBodyHtml". Look at the below code sample,

The above picture clearly shows the how to enable the property to get the work done.

Keep .Neting...