Click here to Skip to main content
Click here to Skip to main content

Store Large Amounts of Data using FCKeditor

, 14 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

mparvez
Software Developer (Senior) icddr,b
Bangladesh Bangladesh
More than 8 years experience on Programming and Project implementation, I was primarily involved with projects for private organization,Govt.(Bangladesh Army,DG Health,RJSC), NGO (SEDF,WFP). Presently I am working at ICDDR,B and enhancing Hospital Management System developed by Microsoft Dynamic NAV and Windows Mobile Application 5.0
 
An active supporter of Open Source technology, my interested areas are ERP, IT Audit, Data warehouse, BI etc.
 
Playing Guitar for 15 years, my interested music style is Blues Rock,Neo Classical.
 
Certification
 
70-540:Microsoft® Windows Mobile® 5.0 - Application Development
MB7-514:Microsoft Dynamics™ NAV 5.0 C/SIDE Introduction
MB7-516:Microsoft Dynamics™ NAV 5.0 Solution Development
MB7-517:Microsoft Dynamics™ NAV 5.0 Installation and Configuration
MB7-515:Microsoft Dynamics™ NAV 5.0 Financials
70-432:Microsoft SQL Server 2008 - Implementation and Maintenance
70-450:PRO: Designing, Optimizing and Maintaining a Database Administrative Solution Using Microsoft SQL Server 2008
70-448:Microsoft SQL Server 2008, Business Intelligence Development and Maintenance
312-50:Certified Ethical Hacker
 
Web :http://masudparvezshabuz.appspot.com
Blog :http://masudparvezshabuz.wordpress.com
linkedin :http://www.linkedin.com/in/masudparvez
Follow on   Google+

Comments and Discussions

 
GeneralMy vote of 1 PinmemberH. Mueller14-Sep-12 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 14 Sep 2012
Article Copyright 2012 by mparvez
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid