private void SaveImg() { if (!Directory.Exists(this.FolderPath)) { Directory.CreateDirectory(this.FolderPath); } File.Copy(PathUtility.CombinePaths(this.TempFolderPath, this.imageName), PathUtility.CombinePaths(this.FolderPath, this.imageName)); }
public void Upload(HttpPostedFileBase file) { if (String.IsNullOrEmpty(this.tempFolder)) { this.tempFolder = Guid.NewGuid().ToString(); } if (!Directory.Exists(this.TempFolderPath)) { Directory.CreateDirectory(this.TempFolderPath); } this.image = file; this.imageName = file.FileName; file.SaveAs(PathUtility.CombinePaths(this.TempFolderPath, this.imageName)); }
private void GenerateWorkbook(List <SalesViewModel> list, string ReportName, HttpApplication application) { // TODO: Replace with List<Product> or else suitable using (ExcelEngine excelEngine = new ExcelEngine()) { excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016; IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; #region Cell Styles IStyle headerStyle = workbook.Styles.Add("HeaderStyle"); headerStyle.Font.Bold = true; headerStyle.Font.Size = 12; headerStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; headerStyle.Color = Color.FromArgb(255, 174, 33); IStyle contentStyle = workbook.Styles.Add("ContentStyle"); contentStyle.VerticalAlignment = ExcelVAlign.VAlignTop; #endregion #region Header Cells worksheet.Range[1, 1].Text = "ID"; worksheet.Range[1, 1].CellStyle = headerStyle; worksheet.SetColumnWidth(1, 4.0); worksheet.Range[1, 2].Text = "Name"; worksheet.Range[1, 2].CellStyle = headerStyle; worksheet.SetColumnWidth(2, 28.0); worksheet.Range[1, 3].Text = "Description"; worksheet.Range[1, 3].CellStyle = headerStyle; worksheet.SetColumnWidth(3, 38.0); worksheet.Range[1, 4].Text = "Price"; worksheet.Range[1, 4].CellStyle = headerStyle; worksheet.SetColumnWidth(4, 16.0); worksheet.Range[1, 5].Text = "Image"; worksheet.Range[1, 5].CellStyle = headerStyle; worksheet.SetColumnWidth(5, 27.86); worksheet.Range[1, 6].Text = "Category"; worksheet.Range[1, 6].CellStyle = headerStyle; worksheet.SetColumnWidth(6, 24.0); worksheet.Range[1, 7].Text = "Status"; worksheet.Range[1, 7].CellStyle = headerStyle; worksheet.SetColumnWidth(7, 8.0); worksheet.Range[1, 8].Text = "Sellings"; worksheet.Range[1, 8].CellStyle = headerStyle; worksheet.SetColumnWidth(8, 8.0); #endregion int startRowIndex = 2; for (int i = startRowIndex; i < (list.Count + startRowIndex); i++) // rows { #region Feeding Content worksheet.Range[i, 1].Text = list[i - startRowIndex].ID.ToString(); worksheet.Range[i, 1].CellStyle = contentStyle; worksheet.Range[i, 1].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; worksheet.Range[i, 2].Text = list[i - startRowIndex].Name; worksheet.Range[i, 2].CellStyle = contentStyle; worksheet.Range[i, 3].Text = list[i - startRowIndex].Description; worksheet.Range[i, 3].CellStyle = contentStyle; worksheet.Range[i, 4].Text = Func.Currencyfy(list[i - startRowIndex].Price); worksheet.Range[i, 4].CellStyle = contentStyle; worksheet.Range[i, 4].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; System.Drawing.Image image = System.Drawing.Image.FromFile(PathUtility.CombinePaths(Config.StoragePathProduct, list[i - startRowIndex].ID.ToString(), list[i - startRowIndex].ImageName)); System.Drawing.Image image_r = Imager.Resize(image, 200, 150, true); IPictureShape shape = worksheet.Pictures.AddPicture(i, 5, image_r); worksheet.SetRowHeightInPixels(i, image_r.Height); worksheet.Range[i, 6].Text = list[i - startRowIndex].Category; worksheet.Range[i, 6].CellStyle = contentStyle; worksheet.Range[i, 7].Text = (list[i - startRowIndex].Status) ? "Active" : "Inactive"; worksheet.Range[i, 7].CellStyle = contentStyle; worksheet.Range[i, 7].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; worksheet.Range[i, 8].Text = list[i - startRowIndex].Sellings.ToString(); worksheet.Range[i, 8].CellStyle = contentStyle; worksheet.Range[i, 8].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; #endregion } workbook.SaveAs($"Report - {ReportName}.xlsx", application.Response, ExcelDownloadType.Open); } }