Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Store Large Amounts of Data using FCKeditor

0.00/5 (No votes)
14 Sep 2012 1  
How to insert and load large amounts of data with formatting using FCKeditor
Sample Image

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here