This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form asp-controller="Home" asp-action="Export"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-4"> | |
<input type="file" id="fileupload" name="files" class="form-control" /> | |
</div> | |
<div class="col-md-3"> | |
<input type="button" name="Upload" value="Upload" id="btnupload" class="btn btn-primary" /> | |
<a href="@Url.Action("Download", "Home")">Download</a> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script> | |
<script type="text/javascript"> | |
$(function () { | |
$('#btnupload').on('click', function () { | |
var fileExtension = ['xls', 'xlsx']; | |
var filename = $('#fileupload').val(); | |
if (filename.length == 0) { | |
alert("Please select a file."); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Import() | |
{ | |
IFormFile file = Request.Form.Files[0]; | |
string folderName = "UploadExcel"; | |
string webRootPath = _hostingEnvironment.WebRootPath; | |
string newPath = Path.Combine(webRootPath, folderName); | |
StringBuilder sb = new StringBuilder(); | |
if (!Directory.Exists(newPath)) | |
{ | |
Directory.CreateDirectory(newPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Download() | |
{ | |
string Files = "wwwroot/UploadExcel/CoreProgramm_ExcelImport.xlsx"; | |
byte[] fileBytes = System.IO.File.ReadAllBytes(Files); | |
System.IO.File.WriteAllBytes(Files, fileBytes); | |
MemoryStream ms = new MemoryStream(fileBytes); | |
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "employee.xlsx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> Export() | |
{ | |
string sWebRootFolder = _hostingEnvironment.WebRootPath; | |
string sFileName = @"Employees.xlsx"; | |
string URL = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, sFileName); | |
FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); | |
var memory = new MemoryStream(); | |
using (var fs = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Create, FileAccess.Write)) | |
{ | |
IWorkbook workbook; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
private readonly IHostingEnvironment _hostingEnv = null; | |
string AppBasePath = null; | |
string ContentRootPath = null; | |
public HomeController(IHostingEnvironment HostingEnv) | |
{ | |
_hostingEnv = HostingEnv; | |
AppBasePath = _hostingEnv.WebRootPath; //path to wwwroot | |
ContentRootPath = _hostingEnv.ContentRootPath; //path to GetBasePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Startup(IConfiguration configuration,IHostingEnvironment _env) | |
{ | |
Configuration = configuration; | |
string sAppPath = _env.ContentRootPath; //Application Base Path | |
string swwwRootPath = _env.WebRootPath; //wwwroot folder path | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mailConfig": { | |
"mailFrom": "info@coreprogramm.com", | |
"host": "smtp.google.com", | |
"portNo": "465", | |
"password": "CorePa$$word" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MailConfig | |
{ | |
public string mailFrom { get; set; } | |
public string host { get; set; } | |
public string password { get; set; } | |
public int portNo { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<MailConfig>(Configuration.GetSection("mailConfig")); | |
services.AddControllersWithViews(); | |
} |
OlderNewer