Example #1
0
        /// <summary>
        /// export_data
        /// </summary>
        public static string export_data(data_table_export_format format, DataSet ds, string temp_directory)
        {
            string destination;
            string file_name;
            Random rnd = new Random(DateTime.Now.Millisecond);

            file_name   = rnd.Next(10000, 1000000000) + "." + format.ToString();
            destination = temp_directory + "\\" + file_name;

            if (format == data_table_export_format.xls)
            {
                #region Check Table Name For Excel Length Limit of 31 Characters
                foreach (DataTable objTable in ds.Tables)
                {
                    if (objTable.TableName.Length > 31)
                    {
                        objTable.TableName = StringFunctions.Right(objTable.TableName, 31);
                    }
                }
                #endregion

                #region Remove Secure Fields From Export
                try
                {
                    foreach (DataTable objTable in ds.Tables)
                    {
                        lookagain : foreach (DataColumn col in objTable.Columns)
                        {
                            string strColName = col.ColumnName.ToLower();
                            if (strColName == "password" || strColName == "pass" || strColName == "exhibitorpassword" || strColName == "administratorpassword" || strColName == "customerpassword")
                            {
                                objTable.Columns.Remove(col.ColumnName);
                                goto lookagain;
                            }
                            if (strColName == "username" || strColName == "user" || strColName == "exhibitorusername" || strColName == "administratorusername" || strColName == "customerusername")
                            {
                                objTable.Columns.Remove(col.ColumnName);
                                goto lookagain;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    General.Debugging.Report.SendError("Error removing secured fields in Excel Spreadsheet for export", ex);
                }
                #endregion

                /* THE OLD WAY
                 *              string xml = WorkbookEngine.CreateWorkbook(ds);
                 *              System.IO.StreamWriter sw = new System.IO.StreamWriter(destination,false);
                 *              sw.Write(xml);
                 *              sw.Close();
                 */

                xpOutputFormat outputFormat;
                outputFormat    = xpOutputFormat.Excel8;
                _xportToolsDemo = new DS2XL();

                //Check if we need to optimize export output for smaller export size. If not, then
                //export will be optimized for speed (default). This option works only for export
                //into XLS file format.
                _xportToolsDemo.OptimizeForSize = false;

                try
                {
                    //Export loaded data
                    ExportDataSetIntoResponse(ds, null, outputFormat, true,
                                              false, _xportToolsDemo, destination);
                }
                finally
                {
                    ReleaseGlobalResources();
                }
            }
            else if (format == data_table_export_format.xml)
            {
                //Remove Spaces From Column Names
                DataTable objTable = ds.Tables[0];
                foreach (DataColumn objColumn in objTable.Columns)
                {
                    if (objColumn.ColumnName.Contains(" "))
                    {
                        objColumn.ColumnName = objColumn.ColumnName.Replace(" ", "");
                    }
                }
                ds.WriteXml(destination);
            }
            else if (format == data_table_export_format.mdb)
            {
                access_tools.create_mdb_file(ds, destination, temp_directory + "\\Templates\\template.mdb");
            }
            else if (format == data_table_export_format.csv)
            {
                text_tools.create_txt_file(ds, destination);
            }
            else if (format == data_table_export_format.txt)
            {
                text_tools.create_txt_file(ds, destination, txt_data_type.tab, "", true);
            }

            return(file_name);
        }
Example #2
0
        /// <summary>
        /// export_data
        /// </summary>
        public static string export_data(data_table_export_format format, DataSet ds, string temp_directory)
        {
            string destination;
            string file_name;
            Random rnd = new Random(DateTime.Now.Millisecond);
            file_name = rnd.Next(10000,1000000000) + "." + format.ToString();
            destination = temp_directory + "\\" + file_name;

            if(format == data_table_export_format.xls)
            {

                #region Check Table Name For Excel Length Limit of 31 Characters
                foreach (DataTable objTable in ds.Tables)
                    if (objTable.TableName.Length > 31)
                        objTable.TableName = StringFunctions.Right(objTable.TableName, 31);
                #endregion

                #region Remove Secure Fields From Export
                try
                {
                    foreach (DataTable objTable in ds.Tables)
                    {
                    lookagain: foreach (DataColumn col in objTable.Columns)
                        {
                            string strColName = col.ColumnName.ToLower();
                            if (strColName == "password" || strColName == "pass" || strColName == "exhibitorpassword" || strColName == "administratorpassword" || strColName == "customerpassword")
                            {
                                objTable.Columns.Remove(col.ColumnName);
                                goto lookagain;
                            }
                            if (strColName == "username" || strColName == "user" || strColName == "exhibitorusername" || strColName == "administratorusername" || strColName == "customerusername")
                            {
                                objTable.Columns.Remove(col.ColumnName);
                                goto lookagain;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    General.Debugging.Report.SendError("Error removing secured fields in Excel Spreadsheet for export", ex);
                }
                #endregion

                /* THE OLD WAY
             		string xml = WorkbookEngine.CreateWorkbook(ds);
                System.IO.StreamWriter sw = new System.IO.StreamWriter(destination,false);
                sw.Write(xml);
                sw.Close();
                */

                xpOutputFormat outputFormat;
                outputFormat = xpOutputFormat.Excel8;
                _xportToolsDemo = new DS2XL();

                //Check if we need to optimize export output for smaller export size. If not, then
                //export will be optimized for speed (default). This option works only for export
                //into XLS file format.
                _xportToolsDemo.OptimizeForSize = false;

                try
                {

                    //Export loaded data
                    ExportDataSetIntoResponse(ds, null, outputFormat, true,
                        false, _xportToolsDemo, destination);
                }
                finally
                {
                    ReleaseGlobalResources();
                }

            }
            else if (format == data_table_export_format.xml)
            {
                //Remove Spaces From Column Names
                DataTable objTable = ds.Tables[0];
                foreach (DataColumn objColumn in objTable.Columns)
                {
                    if (objColumn.ColumnName.Contains(" "))
                        objColumn.ColumnName = objColumn.ColumnName.Replace(" ", "");
                }
                ds.WriteXml(destination);
            }
            else if(format == data_table_export_format.mdb)
            {
                access_tools.create_mdb_file(ds,destination,temp_directory + "\\Templates\\template.mdb");
            }
            else if(format == data_table_export_format.csv)
            {
                text_tools.create_txt_file(ds,destination);
            }
            else if(format == data_table_export_format.txt)
            {
                text_tools.create_txt_file(ds,destination,txt_data_type.tab,"",true);
            }

            return(file_name);
        }