Introduction
In basic ASP.NET, FCKeditor can be easily used to insert large amounts of data.
Step 1 - Download
Download the FCKeditor
from here.
Step 2 - Create Table
CREATE TABLE [dbo].[Document]
(
[Doc ID] [int] NOT NULL,
[Document] [image] NULL
CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED
(
[Doc ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Step 3 - Initialize FCKeditor
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2"
TagPrefix="FCKeditorV2" %>
Using the Code
Insert Information from FCKeditor
private void SaveData()
{
try
{
dc.CreateConnection();
dc.Open();
long id = dc.GetNextID("[Document]", "[Doc ID]");
string strSQL = @"INSERT INTO
[dbo].[Document]
(
[Doc ID]
,[Document]
)
VALUES
(
@id,
@Doc
)";
SqlConnection con = dc.GetConnection();
SqlCommand cmd = new SqlCommand(strSQL, con);
Byte[] rtf = new Byte[FCK.Value.Length];
rtf = Encoding.ASCII.GetBytes(FCK.Value);
SqlParameter fileContent = new SqlParameter();
fileContent.ParameterName = "@Doc";
fileContent.SqlDbType = SqlDbType.Image;
fileContent.Size = rtf.Length;
fileContent.Value = rtf;
SqlParameter vid = new SqlParameter();
vid.ParameterName = "@id";
vid.SqlDbType = SqlDbType.BigInt;
vid.Value = id;
cmd.Parameters.Add(fileContent);
cmd.Parameters.Add(vid);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
dc.Close();
}
}
}
Load Information from FCKeditor
private void LoadData()
{
SqlDataReader dr = null;
try
{
dc.Open();
string strSQL = @"SELECT
[Doc ID]
,[Document]
FROM
[dbo].[Document]";
dr = dc.Read(strSQL);
if (dr.HasRows)
{
dr.Read();
if (dr["Document"].ToString() != "")
{
FCK.Value = System.Text.Encoding.ASCII.GetString((Byte[])dr["Document"]);
}
}
}
catch (Exception ex)
{
}
finally
{
dc.Close();
}
}
References
History
- 12th September, 2012: Initial post