Esempio n. 1
0
        public ActionResult IntroductionDefault()
        {
            ErrorMessage = "";
            string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
            CheckFileStatus CheckFile = new CheckFileStatus();

            ErrorMessage = CheckFile.CheckFile(path);
            if (ErrorMessage == "")
            {
                try
                {
                    //Binding the result to the grid
                    List <PersonDetail> DataSource = CustomersData.list();
                    ViewBag.datasource = DataSource;
                    ErrorMessage       = "";
                }
                catch (HqlConnectionException)
                {
                    ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                }
            }


            return(View());
        }
Esempio n. 2
0
        public ActionResult AsynchronousDefault()
        {
            ErrorMessage = "";
            string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
            CheckFileStatus CheckFile = new CheckFileStatus();

            ErrorMessage = CheckFile.CheckFile(path);
            if (ErrorMessage == "")
            {
                try
                {
                    //Initializing the connection
                    HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                    //To initialize a Hive server connection with secured cluster
                    //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                    //To initialize a Hive server connection with Azure cluster
                    //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                    //Open the HiveServer connection
                    con.Open();

                    //Create a table with data
                    HqlCommand createCommand = new HqlCommand("create external table IF NOT EXISTS AdventureWorks_Person_Contact(contactid int,fullname string,age int,emailaddress string,phoneno string,modifieddate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                    createCommand.ExecuteNonQuery();

                    //Select query with connection
                    HqlCommand command = new HqlCommand("select * from AdventureWorks_Person_Contact limit 100", con);

                    //Executing the query
                    reader         = command.ExecuteReader();
                    page           = 0;
                    skip           = -1;
                    DataCollection = new Dictionary <int, DataResult>();
                    ErrorMessage   = "";
                }
                catch (HqlConnectionException)
                {
                    ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                }
            }

            return(View());
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            CheckFileStatus FileStatus = new CheckFileStatus();
            string          path       = path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));

            ErrorMessage.InnerText = FileStatus.CheckFile(path);
            if (ErrorMessage.InnerText == "")
            {
                try
                {
                    //initializing the connection
                    con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                    //To initialize a Hive server connection with secured cluster
                    //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                    //To initialize a Hive server connection with Azure cluster
                    //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                    //Open the hive server connection
                    con.Open();

                    //Create table for adventure person contacts
                    HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                    createCommand.ExecuteNonQuery();

                    //Executing the query
                    command = new HqlCommand("select * from AdventureWorks_Person_Contact limit 100", con);
                    reader  = command.ExecuteReader();

                    page = 0;
                    Skip = -1;

                    DataCollection = new Dictionary <int, DataResult>();
                }
                catch (HqlConnectionException)
                {
                    ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                }
            }
        }
Esempio n. 4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            if (hdnGroup.Value == "Word")
            {
                CheckFileStatus FileStatus = new CheckFileStatus();
                string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
                ErrorMessage.InnerText = FileStatus.CheckFile(path);
                if (ErrorMessage.InnerText == "")
                {
                    try
                    {
                        //Create a new document
                        WordDocument document = new WordDocument();

                        //Adding new table to the document
                        WTable doctable = new WTable(document);

                        //Adding a new section to the document.
                        WSection section = document.AddSection() as WSection;

                        //Set Margin of the section
                        section.PageSetup.Margins.All = 72;

                        //Set page size of the section
                        section.PageSetup.PageSize = new SizeF(800, 792);

                        //Create Paragraph styles
                        WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
                        style.CharacterFormat.FontName = "Calibri";
                        style.CharacterFormat.FontSize = 11f;

                        //Create a character format for declaring font color and style for the text inside the cell
                        WCharacterFormat charFormat = new WCharacterFormat(document);
                        charFormat.TextColor = System.Drawing.Color.White;
                        charFormat.Bold      = true;

                        //Initializing the hive server connection
                        HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                        //To initialize a Hive server connection with secured cluster
                        //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                        //To initialize a Hive server connection with Azure cluster
                        //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                        con.Open();

                        //Create table for adventure person contacts
                        HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                        createCommand.ExecuteNonQuery();
                        HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con);

                        //Executing the query
                        HqlDataReader reader = command.ExecuteReader();
                        reader.FetchSize = 100;

                        //Fetches the result from the reader and store it in HiveResultSet
                        HiveResultSet result = reader.FetchResult();

                        //Adding headertext for the table
                        doctable.AddRow(true, false);
                        //Creating new cell
                        WTableCell cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        //Adding cell to the row
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);

                        //Reading each row from the fetched result
                        for (int i = 0; i < result.Count(); i++)
                        {
                            HiveRecord records = result[i];
                            doctable.AddRow(true, false);

                            //Reading each data from the row
                            for (int j = 0; j < records.Count; j++)
                            {
                                Object fields = records[j];

                                //Adding new cell to the document
                                cell = new WTableCell(document);

                                //Adding each data to the cell
                                cell.AddParagraph().AppendText(fields.ToString());
                                cell.Width = 75;

                                //Adding cell to the table
                                doctable.Rows[i + 1].Cells.Add(cell);
                                doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51);
                            }
                        }
                        //Adding table to the section
                        section.Tables.Add(doctable);
                        //Save as word 2007 format
                        if (rBtnWord2003.Checked == true)
                        {
                            document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
                        }
                        else if (rBtnWord2007.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment);
                        }
                        //Save as word 2010 format
                        else if (rbtnWord2010.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment);
                        }
                        //Save as word 2013 format
                        else if (rbtnWord2013.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment);
                        }

                        //Closing the hive connection
                        con.Close();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
            }
            else if (hdnGroup.Value == "Excel")
            {
                ErrorMessage.InnerText = "";
                CheckFileStatus FileStatus = new CheckFileStatus();
                string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
                ErrorMessage.InnerText = FileStatus.CheckFile(path);
                if (ErrorMessage.InnerText == "")
                {
                    try
                    {
                        //Instantiate the spreadsheet creation engine.
                        ExcelEngine excelEngine = new ExcelEngine();

                        //Instantiate the excel application object.
                        IApplication application = excelEngine.Excel;

                        //A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
                        //The new workbook will have 1 worksheets
                        IWorkbook workbook = application.Workbooks.Create(1);

                        //The first worksheet object in the worksheets collection is accessed.
                        IWorksheet worksheet = workbook.Worksheets[0];

                        //Adding header text for worksheet
                        worksheet[1, 1].Text = "ContactID";
                        worksheet[1, 2].Text = "FullName";
                        worksheet[1, 3].Text = "Age";
                        worksheet[1, 4].Text = "EmailAddress";
                        worksheet[1, 5].Text = "PhoneNo";
                        worksheet[1, 6].Text = "ModifiedDate";

                        //Initializing the hive server connection
                        HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                        //To initialize a Hive server connection with secured cluster
                        //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                        con.Open();

                        //Create table for adventure person contacts
                        HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                        createCommand.ExecuteNonQuery();

                        //Passing the hive query
                        HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con);

                        //Executing the query
                        HqlDataReader reader = command.ExecuteReader();
                        reader.FetchSize = 100;

                        //Fetches the result from the reader and store it in a seperate set
                        HiveResultSet result = reader.FetchResult();

                        //Reading each row from the fetched result
                        for (int i = 0; i < result.Count(); i++)
                        {
                            HiveRecord records = result[i];

                            //Reading each field from the row
                            for (int j = 0; j < records.Count; j++)
                            {
                                Object fields = records[j];
                                //Assigning each field value to the worksheet based on index
                                worksheet[i + 2, j + 1].Text = fields.ToString();
                            }
                        }
                        worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White;
                        worksheet.Range["A1:F1"].CellStyle.Font.Bold  = true;
                        worksheet.Range["A1:F1"].CellStyle.Color      = System.Drawing.Color.FromArgb(51, 153, 51);
                        worksheet.UsedRange.AutofitColumns();

                        //Saving workbook on user relevant name
                        string fileName = "Sample.xlsx";

                        //conditions for selecting version
                        //Save as Excel 97to2003 format
                        if (rBtn2003.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel97to2003;
                            workbook.SaveAs("Sample.xls", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2007 formt
                        else if (rBtn2007.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2007;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2010 format
                        else if (rbtn2010.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2010;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2013 format
                        else if (rbtn2013.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2013;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }

                        //closing the workwook
                        workbook.Close();

                        //Closing the excel engine
                        excelEngine.Dispose();


                        //Closing the hive connection
                        con.Close();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
            }
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
            CheckFileStatus FileStatus = new CheckFileStatus();

            ErrorMessage.InnerText = FileStatus.CheckFile(path);
            if (ErrorMessage.InnerText == "")
            {
                try
                {
                    //Initializing the hive server connection
                    HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                    //To initialize a Hive server connection with secured cluster
                    //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                    //To initialize a Hive server connection with Azure cluster
                    //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                    con.Open();

                    //Create table for adventure person contacts
                    HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                    createCommand.ExecuteNonQuery();
                    HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con);

                    //Executing the query
                    HqlDataReader reader = command.ExecuteReader();
                    reader.FetchSize = 100;

                    //Fetches the result from the reader and store it in a HiveResultSet set
                    HiveResultSet result = reader.FetchResult();

                    StringWriter stringWriter = new StringWriter();
                    //Htmlwriter for creating table to append the HiveResults
                    using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Border, "1");
                        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse");
                        writer.RenderBeginTag(HtmlTextWriterTag.Table);

                        writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Contact ID");
                        writer.RenderEndTag();

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Full Name");
                        writer.RenderEndTag();

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Age");
                        writer.RenderEndTag();

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Email Address");
                        writer.RenderEndTag();

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Phone No");
                        writer.RenderEndTag();

                        writer.RenderBeginTag(HtmlTextWriterTag.Th);
                        writer.Write("Modified Date");
                        writer.RenderEndTag();

                        writer.RenderEndTag();
                        int count = result.Count();
                        for (int i = 0; i < count; i++)
                        {
                            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                            HiveRecord records = result[i];

                            for (int j = 0; j < records.Count; j++)
                            {
                                Object fields = records[j];
                                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                                writer.Write(fields);
                                writer.RenderEndTag();
                            }
                            writer.RenderEndTag();
                        }
                        writer.RenderEndTag();
                    }
                    //Binding the result to the RTE control
                    string results = stringWriter.ToString();
                    rteControl.RTEContent.InnerHtml = results;

                    //Closing the hive connection
                    con.Close();
                }
                catch (HqlConnectionException)
                {
                    ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                }
            }
        }
Esempio n. 6
0
        private void BindDataSource()
        {
            ErrorMessage.InnerText = "";
            string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
            CheckFileStatus FileStatus = new CheckFileStatus();

            ErrorMessage.InnerText = FileStatus.CheckFile(path);
            if (ErrorMessage.InnerText == "")
            {
                try
                {
                    //Initializing the hive server connection
                    HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                    //To initialize a Hive server connection with secured cluster
                    //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                    //To initialize a Hive server connection with Azure cluster
                    //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                    con.Open();

                    //Create table for adventure person contacts
                    HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                    createCommand.ExecuteNonQuery();
                    HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact limit 100", con);

                    //Executing the query
                    HqlDataReader reader = command.ExecuteReader();
                    reader.FetchSize = int.MaxValue;

                    //Fetches the result from the reader and store it in a HiveResultSet
                    HiveResultSet result = reader.FetchResult();

                    //Initialize the list to add elements in each row
                    BindingList <PersonDetail> resultList = new BindingList <PersonDetail>();

                    //Read each row from the fetched result
                    foreach (HiveRecord rows in result)
                    {
                        //Adding element of each row to the list
                        resultList = new BindingList <PersonDetail>(result.Select(row => new PersonDetail
                        {
                            ContactId    = Convert.ToInt32(row["contactid"]),
                            FullName     = row["fullname"].ToString(),
                            Age          = Convert.ToInt32(row["age"]),
                            EmailAddress = row["emailaddress"].ToString(),
                            PhoneNo      = row["phoneno"].ToString(),
                            ModifiedDate = row["modifieddate"].ToString()
                        }).ToList());
                    }
                    //Binding the result to the grid
                    this.FlatGrid.DataSource = resultList;
                    this.FlatGrid.DataBind();

                    //Closing the hive connection
                    con.Close();
                }
                catch (HqlConnectionException)
                {
                    ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                }
            }
        }
Esempio n. 7
0
        public ActionResult ExportDefault(string SaveOption)
        {
            if (SaveOption == null)
            {
                ErrorMessage = "";
                return(View());
            }
            else if (SaveOption == "Excel 2013" || SaveOption == "Excel 2010" || SaveOption == "Excel 2007" || SaveOption == "Excel 2003" || SaveOption == "CSV")
            {
                ErrorMessage = "";
                string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
                CheckFileStatus CheckFile = new CheckFileStatus();
                ErrorMessage = CheckFile.CheckFile(path);
                if (ErrorMessage == "")
                {
                    try
                    {
                        //Instantiate the spreadsheet creation engine.
                        ExcelEngine excelEngine = new ExcelEngine();

                        //Instantiate the excel application object.
                        IApplication application = excelEngine.Excel;

                        //A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
                        //The new workbook will have 1 worksheets
                        IWorkbook workbook = application.Workbooks.Create(1);

                        //The first worksheet object in the worksheets collection is accessed.
                        IWorksheet worksheet = workbook.Worksheets[0];
                        var        result    = CustomersData.list();
                        ErrorMessage = null;

                        //Adding header text for worksheet
                        worksheet[1, 1].Text = "Contact Id";
                        worksheet[1, 2].Text = "Full Name";
                        worksheet[1, 3].Text = "Age";
                        worksheet[1, 4].Text = "Phone Number";
                        worksheet[1, 5].Text = "Email Id";
                        worksheet[1, 6].Text = "Modified Date";

                        int i = 1;
                        //Reading each row from the fetched result
                        foreach (PersonDetail records in result)
                        {
                            //Reading each data from the row
                            //Assigning each data to the worksheet based on index
                            worksheet[i + 1, 1].Text = records.ContactId;
                            worksheet[i + 1, 2].Text = records.FullName;
                            worksheet[i + 1, 3].Text = records.Age;
                            worksheet[i + 1, 4].Text = records.PhoneNumber;
                            worksheet[i + 1, 5].Text = records.EmailId;
                            worksheet[i + 1, 6].Text = records.ModifiedDate;
                            i++;
                        }
                        //Assigning Header text with cell color
                        worksheet.Range["A1:F1"].CellStyle.Color      = System.Drawing.Color.FromArgb(51, 153, 51);
                        worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White;
                        worksheet.Range["A1:F1"].CellStyle.Font.Bold  = true;
                        worksheet.UsedRange.AutofitColumns();
                        #endregion

                        //Save as .xls format
                        if (SaveOption == "Excel 2003")
                        {
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2007")
                        {
                            workbook.Version = ExcelVersion.Excel2007;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2007));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2010")
                        {
                            workbook.Version = ExcelVersion.Excel2010;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2013")
                        {
                            workbook.Version = ExcelVersion.Excel2013;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013));
                        }
                        //Save as .csv format
                        else if (SaveOption == "CSV")
                        {
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.csv", ",", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.CSV));
                        }
                        //Close the workbook
                        workbook.Close();

                        //Close the excelengine
                        excelEngine.Dispose();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }

                return(View());
            }
            else
            {
                ErrorMessage = "";
                string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
                CheckFileStatus CheckFile = new CheckFileStatus();
                ErrorMessage = CheckFile.CheckFile(path);
                //A new document is created.
                if (ErrorMessage == "")
                {
                    try
                    {
                        WordDocument document = new WordDocument();

                        //Adding new table to the document
                        WTable doctable = new WTable(document);

                        //Adding a new section to the document.
                        WSection section = document.AddSection() as WSection;

                        //Set Margin of the section
                        section.PageSetup.Margins.All = 72;

                        //Set page size of the section
                        section.PageSetup.PageSize = new SizeF(800, 792);

                        //Create Paragraph styles
                        WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
                        style.CharacterFormat.FontName = "Calibri";
                        style.CharacterFormat.FontSize = 11f;

                        //Reading the data from the table
                        var result = CustomersData.list();
                        doctable.AddRow(true, false);

                        //creating new cell
                        WTableCell cell = new WTableCell(document);

                        //Create a character format for declaring font color and style for the text inside the cell
                        WCharacterFormat charFormat = new WCharacterFormat(document);
                        charFormat.TextColor = System.Drawing.Color.White;
                        charFormat.Bold      = true;

                        //Adding header text for the table
                        cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        //Adding cell to rows
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat);
                        cell.Width = 90;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat);
                        cell.Width = 90;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 180;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat);
                        cell.Width = 125;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);

                        int i = 1;
                        //Reading each row from the fetched result
                        foreach (PersonDetail records in result)
                        {
                            doctable.AddRow(true, false);

                            //Assigning fetched result to the cell
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.ContactId.ToString());
                            cell.Width = 75;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.FullName.ToString());
                            cell.Width = 90;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.Age.ToString());
                            cell.Width = 75;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.PhoneNumber.ToString());
                            cell.Width = 90;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.EmailId.ToString());
                            cell.Width = 180;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.ModifiedDate.ToString());
                            cell.Width = 125;
                            doctable.Rows[i].Cells.Add(cell);

                            i++;
                        }
                        //Adding table to the section
                        section.Tables.Add(doctable);

                        #region saveOption
                        //Save as .doc Word 97-2003 format
                        if (SaveOption == "Word 97-2003")
                        {
                            return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2007 format
                        else if (SaveOption == "Word 2007")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2010 format
                        else if (SaveOption == "Word 2010")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2013 format
                        else if (SaveOption == "Word 2013")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }

                        #endregion saveOption
                    }

                    catch (HqlConnectionException)
                    {
                        ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
                return(View());
            }
        }