Here is my problem: I need to store HTML in a MySQL database. Afterwards, I need to be able to retrieve the HTML and have it be valid HTML that a browser can render.
My question: How can I store HTML in a MySQL database using .Net? How do I retrieve it afterwards? As this is the design p开发者_StackOverflow社区hase, I can create the database any way that is needed. Thank you.
P.S. I have seen some posts on this using PHP and JAva but I am not using PHP or Java and those posts did not really answer my question.
You can store HTML as a binary stream in MySQL's BLOB format. Also you can retrieve it in .NET.
To retrieve and store it, you can simply use Byte[] in .NET.
This is a sample using BLOB: http://msdn.microsoft.com/en-us/library/87z0hy49.aspx
First of all, do want want to store a file or just the html text? Since you say php, I take it that u are using web based. If so, I suggest storing the html text as string.
First of read the content of the html file using something like this:
using( StreamReader reader = new StreamReader( @"c:\index.html" ) )
{
String line = String.Emtpy;
while( (line = reader.ReadLine()) != null )
{
Console.WriteLine( line );
}
}
Then, just do a normal insertion of string in a reasonable string data type of MySQL. (Cant recall, but if really need alot, can consider BLOB)
After that, when you want to display, at the code behind of the aspx page, retrieve the html as string, and use use
Response.Write()
You'll be needing the .NET driver for MySQL. If you have experience building C# applications that connect to MSSQL or any other database server, then you'll know where to go next.
As far as storing in the database is concerned, have a text
field in your table, to store the HTML code in.
精彩评论