protected void ImportButton_Click(object sender, EventArgs e) { Control destinationControl = Globals.FindControlRecursiveDown(Page, PanesDropDownList.SelectedValue.Replace("dnn_", string.Empty)); if (ImportFileUpload.HasFile) { // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic"); if (File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } Stream stream = ImportFileUpload.FileContent; Document doc = new Document(stream); string filePath = Server.MapPath("~/temp/"); if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); filePath += "\\" + System.Guid.NewGuid().ToString(); doc.Save(filePath, SaveFormat.Html); string outputText = File.ReadAllText(filePath); if (destinationControl != null) destinationControl.Controls.Add(new LiteralControl(outputText)); else OutputLiteral.Text = outputText; } }
protected void ImportButton_Click(object sender, EventArgs e) { Control destinationControl = Globals.FindControlRecursiveDown(Page, PanesDropDownList.SelectedValue.Replace("dnn_", string.Empty)); if (ImportFileUpload.HasFile) { // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic"); if (File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } // Initialize the stream to read the uploaded file. Stream myStream = ImportFileUpload.FileContent; //open document Document pdfDocument = new Document(myStream); string path = Server.MapPath(".") + "//" + ImportFileUpload.FileName.Replace(".pdf", ".html"); pdfDocument.Save(path, SaveFormat.Html); string extractedText = File.ReadAllText(path); if (destinationControl != null) destinationControl.Controls.Add(new LiteralControl(extractedText)); else OutputLiteral.Text = extractedText; } else { OutputLiteral.Text = "Please Upload File"; } }
// // GET: /AsposeExporter/ public void Index(string Format="pdf") { string baseURL = Request.Url.Authority; if (Request.ServerVariables["HTTPS"] == "on") { baseURL = "https://" + baseURL; } else { baseURL = "http://" + baseURL; } // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Words.lic"); if (System.IO.File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } string refURL = Request.UrlReferrer.AbsoluteUri; string html = new WebClient().DownloadString(refURL); // To make the relative image paths work, base URL must be included in head section html = html.Replace("</head>", string.Format("<base href='{0}'></base></head>", baseURL)); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(html)); Document doc = new Document(stream); string fileName = System.Guid.NewGuid().ToString() + "." + Format; doc.Save(System.Web.HttpContext.Current.Response, fileName, ContentDisposition.Inline, null); System.Web.HttpContext.Current.Response.End(); }
public static void Run() { try { var lic = new License(); lic.SetLicense(@"E:\Aspose\License\Aspose.Tasks.lic"); // ExStart:WriteFormulasInExtendedAttributesToMPP // Create project instance string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); Project project = new Project(dataDir + "Project1.mpp"); project.Set(Prj.NewTasksAreManual, false); // Create new custom field (Task Text1) with formula which will double task cost ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition(); attr.FieldId = ExtendedAttributeTask.Text1.ToString("D"); attr.Alias = "Double Costs"; attr.Formula = "[Cost]*2"; project.ExtendedAttributes.Add(attr); // Add a task Task task = project.RootTask.Children.Add("Task"); // Set task cost task.Set(Tsk.Cost, 100); // Save project project.Save(dataDir + "WriteFormulasInExtendedAttributesToMPP_out.mpp", SaveFileFormat.MPP); // ExEnd:WriteFormulasInExtendedAttributesToMPP } catch(Exception ex) { Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx."); } }
private void GeneratePreviewImages() { var previewFile = Path.Combine((string)asm.GetType("Workshare.Utilities.LocalCopyOfFileManager").GetProperty("ManagedFolder").GetValue(_lcfm), "0.jpg"); var license = new License(); license.SetLicense(GetLicence()); var document = new Document(FileName); var saveOptions = new ImageSaveOptions(SaveFormat.Jpeg) { UseHighQualityRendering = true, JpegQuality = 100 }; for (var i = 0; i < document.PageCount; i++) { saveOptions.PageIndex = i; var pageImageFileName = string.Format("{0}{1}.jpg", (string)asm.GetType("Workshare.Utilities.LocalCopyOfFileManager").GetProperty("ManagedFolder").GetValue(_lcfm) + "\\", i); document.Save(pageImageFileName, saveOptions); if (PreviewImage == null) { PreviewImage = new Bitmap(previewFile); Events.RaiseEvent(this, ThumbnailGenerated); } PreviewImages.Add(new Bitmap(pageImageFileName)); } }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { // Create a License object License license = new License(); // Set the license of Aspose.Cells to avoid the evaluation limitations license.SetLicense(dataDir + "Aspose.Cells.lic"); } catch (Exception ex) { Console.WriteLine(ex.Message); } // Instantiate a Workbook object that represents Excel file. Workbook wb = new Workbook(); // When you create a new workbook, a default "Sheet1" is added to the workbook. Worksheet sheet = wb.Worksheets[0]; // Access the "A1" cell in the sheet. Cell cell = sheet.Cells["A1"]; // Input the "Hello World!" text into the "A1" cell cell.PutValue("Hello World!"); // Save the Excel file. wb.Save(dataDir + "MyBook_out.xlsx", SaveFormat.Excel97To2003); // ExEnd:1 }
/// <summary> /// Sets the license stream. /// </summary> public override void SetLicense() { License license = new License(); license.SetLicense(AttachmentResources.LicenseFileName); Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License(); pdfLicense.SetLicense(AttachmentResources.LicenseFileName); }
/// <summary> /// Constroi um objeto recuperando e definindo a licença de uso /// </summary> public PDF2ImageAsposePDFConverter() { var assembly = Assembly.GetExecutingAssembly(); License license = new License(); using (Stream stream = assembly.GetManifestResourceStream("Carubbi.PDF.Assets.Aspose.Total.lic")) { license.SetLicense(stream); } }
static void Main(string[] args) { Aspose.Diagram.License lic = new License(); lic.SetLicense(@"Aspose.Diagram.lic"); Diagram diagram = new Diagram("./../../Samples/Basic Flowchart.vsd"); diagram.Save("./../../Output/Output.pdf", SaveFileFormat.PDF); Console.WriteLine("Done"); Console.ReadKey(); }
public static void Run() { // ExStart:ApplyLicenseByPath // Set path of the license file, i.e. c:\temp\ string dataDir = @"c:\temp\"; License license = new License(); license.SetLicense(dataDir + "Aspose.Diagram.lic"); // ExEnd:ApplyLicenseByPath }
public void LicenseFromFileNoPath() { // Copy a license to the bin folder so the example can execute. string dstFileName = Path.Combine(AssemblyDir, "Aspose.Words.lic"); File.Copy(TestLicenseFileName, dstFileName); //ExStart //ExFor:License //ExFor:License.#ctor //ExFor:License.SetLicense(String) //ExId:LicenseFromFileNoPath //ExSummary:In this example Aspose.Words will attempt to find the license file in the embedded resources or in the assembly folders. License license = new License(); license.SetLicense("Aspose.Words.lic"); //ExEnd // Cleanup by removing the license. license.SetLicense(""); File.Delete(dstFileName); }
static void Main(string[] args) { Aspose.Diagram.License lic = new License(); lic.SetLicense(@"Aspose.Diagram.lic"); Diagram diagram = new Diagram("./../../Samples/Sample.vdx"); diagram.Save("./../../Output/Output.html", SaveFileFormat.HTML); Console.WriteLine("Done"); Console.ReadKey(); }
public LetterGenerator(IAdjustmentLettersConfiguration config, IAsposeWrapper aspose) { this.pdfTemplate = config.PdfLetterTemplate; var license = new License(); //// Instantiate license file license.SetLicense("Aspose.Pdf.lic"); //// Set the value to indicate that license will be embedded in the application license.Embedded = true; this.aspose = aspose; }
public static void Run() { // ExStart:ApplyLicenseUsingFileStream // Set path of the license file, i.e. c:\temp\ string dataDir = @"c:\temp\"; // Load an existing Visio file in the stream FileStream LicStream = new FileStream(dataDir + "Aspose.Diagram.lic", FileMode.Open); License license = new License(); license.SetLicense(LicStream); // ExEnd:ApplyLicenseUsingFileStream }
internal static void SetUnlimitedLicense() { if (File.Exists(TestLicenseFileName)) { // This shows how to use an Aspose.Words license when you have purchased one. // You don't have to specify full path as shown here. You can specify just the // file name if you copy the license file into the same folder as your application // binaries or you add the license to your project as an embedded resource. License license = new License(); license.SetLicense(TestLicenseFileName); } }
protected void Application_Start(object sender, EventArgs e) { // TODO 0 Do not ship source code of this demo project with Aspose.Words.lic embedded in the project. Delete Aspose.Words.lic and this comment before shipping. using (Stream licenseStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FirstFloor.Documents.Aspose.Web.Aspose.Words.lic")) { if (licenseStream != null) { License license = new License(); license.SetLicense(licenseStream); } } }
static void Main(string[] args) { Aspose.Diagram.License lic = new License(); lic.SetLicense(@"Aspose.Diagram.lic"); //Load adiagram Diagram diagram = new Diagram("./../../Samples/Drawing1.vsd"); //Get first page if (diagram.Pages.Count == 0) { return; } Page page0 = diagram.Pages[0]; //Get the rectangle master Master masterRectangle = null; foreach (Master master in diagram.Masters) if (master.Name == "Rectangle") { masterRectangle = master; break; } if (masterRectangle == null) { return; } //Get next shape ID long nextID = 100; //Set shape properties and add it in the shapes' collection Shape shape = new Shape(); shape.ID = nextID; shape.Master = masterRectangle; shape.MasterShape = masterRectangle.Shapes[0]; shape.Type = TypeValue.Shape; shape.XForm.Height.Value = 1; shape.XForm.Width.Value = 2; shape.XForm.PinX.Value = 2; shape.XForm.PinY.Value = 2; shape.XForm.LocPinX.Ufe.F = "Width*0.5"; shape.XForm.LocPinY.Ufe.F = "Height*0.5"; shape.Text.Value.Add(new Txt("Some Text")); page0.Shapes.Add(shape); diagram.Save("./../../Output/Output.vdx", SaveFileFormat.VDX); Console.WriteLine("Done"); Console.ReadKey(); }
/// <summary> /// Instantiate a comparison service /// </summary> public ComparisonService(ComparisonWidgetSettings settings) { //Set new context name _contextName = Guid.NewGuid().ToString(); //Set settings _settings = settings; //Set Viewer license if (!String.IsNullOrEmpty(settings.LicensePath)) { License lic = new License(); lic.SetLicense(settings.LicensePath); } }
static void Main(string[] args) { Aspose.Diagram.License lic = new License(); lic.SetLicense("Aspose.Diagram.lic"); Diagram diagram = new Diagram("./../../Samples/Sample.vdx"); SWFSaveOptions options = new SWFSaveOptions(); options.SaveFormat = SaveFileFormat.SWF; // Exclude the embedded viewer options.ViewerIncluded = false; diagram.Save("./../../Output/Output.swf", options); Console.WriteLine("Done"); Console.ReadKey(); }
//ExStart:ApplyLicense /// <summary> /// Applies product license /// </summary> public static void ApplyLicense() { try { // initialize License License lic = new License(); // apply license lic.SetLicense(System.Configuration.ConfigurationManager.AppSettings["LicensePath"].ToString()); } catch (Exception exp) { } }
//ExEnd:MapDestinationFilePath //ExStart:ApplyLicense /// <summary> /// Applies product license /// </summary> public static void ApplyLicense() { try { // initialize License License lic = new License(); // apply license lic.SetLicense(LicenseFilePath); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
public void LicenseFromStream() { Stream myStream = File.OpenRead(TestLicenseFileName); try { //ExStart //ExFor:License.SetLicense(Stream) //ExId:LicenseFromStream //ExSummary:Initializes a license from a stream. License license = new License(); license.SetLicense(myStream); //ExEnd } finally { myStream.Close(); } }
public MainForm() { InitializeComponent(); this.btnAddMaster.Enabled = false; this.btnAddShape.Enabled = false; this.btnEditShape.Enabled = false; this.btnRemoveShape.Enabled = false; this.btnSave.Enabled = false; this.btnLayout.Enabled = false; this.btnConnectShapes.Enabled = false; this.CreateLayoutOptions(); this.cmbLayoutStyle.Enabled = false; this.cmbLayoutDirection.Enabled = false; this.btnSwf.Enabled = false; this.btnPrint.Enabled = false; License license = new License(); license.SetLicense("Aspose.Diagram.lic"); }
protected void Page_Load(object sender, EventArgs e) { try { LBL_Message.Text = ""; EntityId = Request.QueryString["id"] == null ? Guid.Empty : new Guid(Request.QueryString["id"]); string OrgName = Request.QueryString["orgname"] == null ? "" : Request.QueryString["orgname"]; EntityName = Request.QueryString["typename"] == null ? "" : Request.QueryString["typename"]; if (EntityId != Guid.Empty && EntityName != "" && OrgName != "") { CreateService(ConfigurationManager.AppSettings["ServerName"], OrgName, ConfigurationManager.AppSettings["Login"], ConfigurationManager.AppSettings["Password"], ConfigurationManager.AppSettings["Domain"]); try { string LicenseFilePath = ConfigurationManager.AppSettings["LicenseFilePath"]; // Check for license and apply if exists if (File.Exists(LicenseFilePath)) { License license = new License(); license.SetLicense(LicenseFilePath); } } catch { } if (!IsPostBack) { LoadDataInDropDowns(EntityName); } } else { LBL_Message.Text = "Parameters are not correct, Please save the record first."; } } catch (Exception ex) { LBL_Message.Text = "Error has occured. Details: " + ex.Message; } }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { // Create a License object License license = new License(); // Set the license of Aspose.Cells to avoid the evaluation limitations license.SetLicense("Aspose.Cells.lic"); } catch (Exception ex) { Console.WriteLine(ex.Message); } // Creating a file stream containing the Excel file to be opened FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open); // Instantiate a Workbook object that represents the existing Excel file Workbook workbook = new Workbook(fstream); // Get the reference of "A1" cell from the cells collection of a worksheet Cell cell = workbook.Worksheets[0].Cells["A1"]; // Put the "Hello World!" text into the "A1" cell cell.PutValue("Hello World!"); // Save the Excel file workbook.Save(dataDir + "HelloWorld_out.xlsx"); // Closing the file stream to free all resources fstream.Close(); // ExEnd:1 }
private void ExportData(string value) { try { // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic"); if (File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } // open and read file FileStream fstream = new FileStream((Server.MapPath("~/Addons/Aspose.SiteFinity.FormBuilder.ToExcel/uploads/AsposeDynamicFormsDataFile.xlsx")), FileMode.Open, FileAccess.Read); //Instantiating a Workbook object //Opening the Excel file through the file stream Workbook workbook = new Workbook(fstream); //Accessing a worksheet using its sheet name Worksheet worksheet = workbook.Worksheets["Data"]; DataTable dataTable; dataTable = worksheet.Cells.Rows.Count <= 0 ? worksheet.Cells.ExportDataTableAsString(0, 0, 1, 1, true) : worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, 8, true); //Closing the file stream to free all resources fstream.Close(); //Instantiate a new Workbook Workbook book = new Workbook(); //Clear all the worksheets book.Worksheets.Clear(); //Add a new Sheet "Data"; Worksheet sheet = book.Worksheets.Add("Data"); // import data in to sheet sheet.Cells.ImportDataTable(dataTable, true, "A1"); // Apply Hearder Row/First Row text to Bold Aspose.Cells.Style objStyle = workbook.CreateStyle(); objStyle.Font.IsBold = true; StyleFlag objStyleFlag = new StyleFlag(); objStyleFlag.FontBold = true; sheet.Cells.ApplyRowStyle(0, objStyle, objStyleFlag); //Auto-fit all the columns book.Worksheets[0].AutoFitColumns(); //Create unique file name string fileName = System.Guid.NewGuid().ToString() + "." + value; //Save workbook as per export type book.Save(this.Response, fileName, ContentDisposition.Attachment, GetSaveFormat(value)); Response.Flush(); } catch (Exception exc) { } }
/// <summary> /// Applies the product license /// </summary> private static void SetInternalLicense() { License license = new License(); license.SetLicense(LicensePath); }
protected void ExportButton_Click(object sender, EventArgs e) { StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); if (ExportDataSource != null) { this.AllowPaging = false; this.DataSource = ExportDataSource; this.DataBind(); } this.RenderBeginTag(hw); this.HeaderRow.RenderControl(hw); foreach (GridViewRow row in this.Rows) { row.RenderControl(hw); } this.FooterRow.RenderControl(hw); this.RenderEndTag(hw); string heading = string.IsNullOrEmpty(ExportFileHeading) ? string.Empty : ExportFileHeading; string pageSource = sw.ToString(); // Check for license and apply if exists if (File.Exists(LicenseFilePath)) { License license = new License(); license.SetLicense(LicenseFilePath); } using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(pageSource))) { var loadOptions = new LoadOptions(LoadFormat.Html) { ConvertNumericData = false }; Workbook workbook = new Workbook(stream, loadOptions); Worksheet worksheet = workbook.Worksheets[0]; worksheet.AutoFitColumns(); worksheet.AutoFitRows(); Aspose.Cells.Cells cells = worksheet.Cells; Range range = worksheet.Cells.MaxDisplayRange; int tcols = range.ColumnCount; int trows = range.RowCount; for (int i = 0; i < trows; i++) { for (int j = 0; j < tcols; j++) { if (cells[i, j].Type != CellValueType.IsNull) { Aspose.Cells.Style style = cells[i, j].GetStyle(); if (i == 0) { style.Font.IsBold = true; } style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.TopBorder].Color = Color.Black; style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.BottomBorder].Color = Color.Black; style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.LeftBorder].Color = Color.Black; style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.RightBorder].Color = Color.Black; cells[i, j].SetStyle(style); } } } worksheet.Cells.InsertColumn(0); worksheet.Cells.InsertRow(0); worksheet.Cells["B1"].HtmlString = heading; worksheet.Cells.InsertRow(0); worksheet.Cells.InsertRow(2); Aspose.Cells.Style style2 = worksheet.Cells["B2"].GetStyle(); style2.Font.Size = 20; style2.Borders.SetStyle(CellBorderType.None); worksheet.Cells["B2"].SetStyle(style2); string extension = ExcelOutputFormat.ToString().ToLower(); if (string.IsNullOrEmpty(extension)) extension = "xls"; string fileNameWithExtension = System.Guid.NewGuid() + "." + extension; if (!string.IsNullOrEmpty(ExportOutputPathOnServer) && Directory.Exists(ExportOutputPathOnServer)) { try { workbook.Save(ExportOutputPathOnServer + "\\" + fileNameWithExtension); } catch (Exception) { } } workbook.Save(HttpContext.Current.Response, fileNameWithExtension, ContentDisposition.Inline, GetSaveFormat(ExcelOutputFormat.ToString())); HttpContext.Current.Response.End(); } }
// Save data to excel file protected void ProcessButton_Click(object sender, EventArgs e) { try { // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic"); if (File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } //Creating a file stream containing the Excel file to be opened FileStream fstream = new FileStream(Server.MapPath("~/Addons/Aspose.SiteFinity.FormBuilder.ToExcel/uploads/AsposeDynamicFormsDataFile.xlsx"), FileMode.Open, FileAccess.Read); //Instantiating a Workbook object //Opening the Excel file through the file stream Workbook workbook = new Workbook(fstream); //Accessing a worksheet using its sheet name //Worksheet worksheet = workbook.Worksheets["Data"]; //Worksheet worksheet1 = workbook.Worksheets["Settings"]; Worksheet worksheet = workbook.Worksheets["Data"]; Worksheet worksheet1 = workbook.Worksheets["Settings"]; //Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable DataTable dataTable = null; if (worksheet.Cells.Rows.Count <= 0) { dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, 1, 1, true); } else { dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.Columns.Count, true); } //Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable from setting DataTable dataTable1 = worksheet1.Cells.ExportDataTableAsString(0, 0, worksheet1.Cells.Rows.Count, 10, true); if (dataTable1 != null) { if (dataTable != null) { if (dataTable.Columns.Count <= 1) { dataTable.Columns.RemoveAt(0); } foreach (DataRow row in dataTable1.Rows) { if (!row[1].ToString().Trim().Equals("Title") && !row[1].ToString().Trim().Equals("Success")) { foreach (string strItem in row[2].ToString().Trim().Split(';')) { if (!strItem.Trim().Equals("")) { if (dataTable.Columns[strItem.Trim()] == null) { dataTable.Columns.Add(strItem.Trim()); } } } } } } } //Closing the file stream to free all resources fstream.Close(); DataRow dr = dataTable.NewRow(); foreach (Control ctrl in myPlaceHolder.Controls) { if (ctrl != null) { if (ctrl is TextBox) { dr[ctrl.ID] = ((TextBox)ctrl).Text.Trim(); continue; } if (ctrl is RadioButton) { if (((RadioButton)ctrl).Checked) { dr[ctrl.ID] = ((RadioButton)ctrl).Text.Trim(); continue; } } if (ctrl is CheckBox) { if (((CheckBox)ctrl).Checked) { dr[ctrl.ID] = ((CheckBox)ctrl).Text.Trim(); continue; } } if (ctrl is DropDownList) { dr[ctrl.ID] = ((DropDownList)ctrl).SelectedItem.Text.Trim(); continue; } } } dataTable.Rows.Add(dr); workbook.Worksheets.RemoveAt("Data"); worksheet = workbook.Worksheets.Add("Data"); worksheet.Cells.ImportDataTable(dataTable, true, "A1"); // Apply Hearder Row/First Row text to Bold Aspose.Cells.Style objStyle = workbook.CreateStyle(); objStyle.Font.IsBold = true; //Bold style flag options StyleFlag objStyleFlag = new StyleFlag(); objStyleFlag.FontBold = true; //Apply this style to row 1 Row row1 = workbook.Worksheets[0].Cells.Rows[0]; row1.ApplyStyle(objStyle, objStyleFlag); worksheet.Cells.ApplyRowStyle(0, objStyle, objStyleFlag); worksheet.Cells.ApplyRowStyle(0, objStyle, objStyleFlag); //Auto-fit all the columns workbook.Worksheets["Data"].AutoFitColumns(); workbook.Save(Server.MapPath("~/Addons/Aspose.SiteFinity.FormBuilder.ToExcel/uploads/AsposeDynamicFormsDataFile.xlsx"), SaveFormat.Xlsx); error_msg.Visible = false; success_msg.Visible = true; } catch (Exception exc) { success_msg.Visible = false; error_msg.Visible = true; error_msg.InnerText = exc.Message; } }
//Form Initiating by creating dynamic controls from Excel sheet private void InitForm() { try { // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic"); if (File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } DataTable dataTable = null; if (Session["AsposeDynamicFormsdataTable"] == null) { //Creating a file stream containing the Excel file to be opened FileStream fstream = new FileStream(Server.MapPath("~/Addons/Aspose.SiteFinity.FormBuilder.ToExcel/uploads/AsposeDynamicFormsDataFile.xlsx"), FileMode.Open, FileAccess.Read); //Instantiating a Workbook object //Opening the Excel file through the file stream Workbook workbook = new Workbook(fstream); //Accessing a worksheet using its sheet name Worksheet worksheet = workbook.Worksheets["Settings"]; //Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, 10, true); //Closing the file stream to free all resources fstream.Close(); dataTable.DefaultView.Sort = "[Sort ID] ASC"; dataTable = dataTable.DefaultView.ToTable(); Session["AsposeDynamicFormsdataTable"] = dataTable; } else { dataTable = (DataTable)Session["AsposeDynamicFormsdataTable"]; } if (dataTable != null) { if (dataTable.Rows.Count > 0) { string fieldType = "Text"; int rows = 0; foreach (DataRow row in dataTable.Rows) { if (!row[7].ToString().Trim().ToLower().Equals("false")) { rows += 1; fieldType = row[1].ToString(); switch (fieldType) { case "Title": { lblTitle.Text = row[4].ToString().Trim(); } break; case "Success": { success_msg.InnerText = row[4].ToString().Trim(); } break; case "Text": { Label lbl = new Label(); LiteralControl table = new LiteralControl("<tr><td>"); lbl.ID = "lbl" + row[2].ToString(); lbl.Text = row[3].ToString(); lbl.Text = lbl.Text + " : "; myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(lbl); table = new LiteralControl("</td>"); myPlaceHolder.Controls.Add(table); TextBox textBox = new TextBox(); textBox.ID = row[2].ToString().Trim(); textBox.Attributes.Add("placeholder", row[4].ToString().Trim()); textBox.CssClass = "myinput"; table = new LiteralControl("<td>"); if (myPlaceHolder.FindControl(textBox.ID) == null) { myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(textBox); table = new LiteralControl("</td></tr>"); myPlaceHolder.Controls.Add(table); } } break; case "MultiText": { Label lbl = new Label(); lbl.ID = "lbl" + row[2].ToString().Trim(); LiteralControl table = new LiteralControl("<tr><td>"); lbl.Text = row[3].ToString().Trim(); lbl.Text = lbl.Text + " : "; myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(lbl); table = new LiteralControl("</td>"); myPlaceHolder.Controls.Add(table); TextBox textBox = new TextBox(); textBox.ID = row[2].ToString().Trim(); textBox.Attributes.Add("placeholder", row[4].ToString().Trim()); textBox.TextMode = TextBoxMode.MultiLine; textBox.CssClass = "myinput"; table = new LiteralControl("<td>"); if (myPlaceHolder.FindControl(textBox.ID) == null) { myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(textBox); table = new LiteralControl("</td></tr>"); myPlaceHolder.Controls.Add(table); } } break; case "Radio": { Label lbl = new Label(); LiteralControl table = new LiteralControl("<tr><td>"); lbl.ID = "lbl" + row[2].ToString().Trim(); lbl.Text = row[3].ToString().Trim(); lbl.Text = lbl.Text + " : "; myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(lbl); table = new LiteralControl("</td>"); myPlaceHolder.Controls.Add(table); int i = 0; table = new LiteralControl("<td>"); myPlaceHolder.Controls.Add(table); foreach (string strItem in row[2].ToString().Trim().Split(';')) { if (!strItem.Equals("")) { RadioButton radioButton = new RadioButton(); radioButton.GroupName = "RadioGroup" + rows.ToString(); if (row[4].ToString().Trim().Split(';').Length >= i) { radioButton.Text = row[4].ToString().Trim().Split(';')[i]; radioButton.ID = row[2].ToString().Trim().Split(';')[i]; if (i == 0) { radioButton.Checked = true; } } if (myPlaceHolder.FindControl(radioButton.ID) == null) { myPlaceHolder.Controls.Add(radioButton); } i++; } } table = new LiteralControl("</td></tr>"); myPlaceHolder.Controls.Add(table); } break; case "Check": { Label lbl = new Label(); LiteralControl table = new LiteralControl("<tr><td>"); lbl.ID = "lbl" + row[2].ToString().Trim(); lbl.Text = row[3].ToString().Trim(); lbl.Text = lbl.Text + " : "; myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(lbl); table = new LiteralControl("</td>"); myPlaceHolder.Controls.Add(table); int i = 0; table = new LiteralControl("<td>"); myPlaceHolder.Controls.Add(table); foreach (string strItem in row[4].ToString().Trim().Split(';')) { if (!strItem.Equals("")) { CheckBox checkBox = new CheckBox(); checkBox.Style.Add("margin-left", "2px"); if (row[4].ToString().Trim().Split(';').Length >= i) { checkBox.Text = row[4].ToString().Trim().Split(';')[i]; checkBox.ID = row[2].ToString().Trim().Split(';')[i]; } if (myPlaceHolder.FindControl(checkBox.ID) == null) { myPlaceHolder.Controls.Add(checkBox); } i++; } } table = new LiteralControl("</td></tr>"); myPlaceHolder.Controls.Add(table); } break; case "DropDown": { Label lbl = new Label(); lbl.ID = "lbl" + row[2].ToString().Trim(); lbl.Text = row[3].ToString().Trim(); lbl.Text = lbl.Text + " : "; LiteralControl table = new LiteralControl("<tr><td>"); myPlaceHolder.Controls.Add(table); myPlaceHolder.Controls.Add(lbl); table = new LiteralControl("</td>"); myPlaceHolder.Controls.Add(table); DropDownList dropdownList = new DropDownList(); dropdownList.ID = row[2].ToString().Trim(); dropdownList.CssClass = "myinput"; table = new LiteralControl("<td>"); myPlaceHolder.Controls.Add(table); foreach (string strItem in row[4].ToString().Trim().Split(';')) { if (!strItem.Equals("")) { dropdownList.Items.Add(strItem); } } if (myPlaceHolder.FindControl(dropdownList.ID) == null) { myPlaceHolder.Controls.Add(dropdownList); table = new LiteralControl("</td></tr>"); myPlaceHolder.Controls.Add(table); } } break; default: break; } } } } } } catch (Exception exc) { success_msg.Visible = false; error_msg.Visible = true; error_msg.InnerText = exc.Message; } }