I work on asp.net razor page with .net core 7 . i face issue i can't convert this function from type script to csharp asp.net razor page
and before convert this code to csharp so what this code do or what is job this function do
so can you help me please ?
TypeScript
public uploadData(e: any) {
this.tableData = null;
this.tableTitle = null;
this.tableRecords = [];
this.totalPageCount = 0;
this.dataService.StockList = null;
// let af = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']
console.log(e.target.files[0]);
/* wire up file reader */
const target: DataTransfer = (e.target);
if (target.files.length !== 1) {
throw new Error('Cannot use multiple files');
}
// if (!XLSX.includes(af, e.target.files[0].type)) {
// throw new Error('Cannot use multiple files');
// }
let reader: FileReader = new FileReader();
reader.readAsBinaryString(target.files[0]);
reader.onload = (e: any) => {
/* create workbook */
const binarystr: string = e.target.result;
const wb: XLSX.WorkBook = XLSX.read(binarystr, { type: 'binary' });
/* selected the first sheet */
const wsname: string = wb.SheetNames[0];
const ws: XLSX.WorkSheet = wb.Sheets[wsname];
/* save data */
const data = XLSX.utils.sheet_to_json(ws); // to get 2d array pass 2nd parameter as object {header: 1}
console.log(data); // Data will be logged in array format containing objects
let LengthErr = "";
let QtyErr = "";
this.dataService.StockList = new Array();
data.forEach((element: any) => {
console.log(element)
const Bin = element;
if (Bin.BINNO.toString().trim().length != 9) {
LengthErr = element.BINNO;
}
if (Bin.QTY >= 10) {
QtyErr = element.BINNO;
}
this.dataService.StockList.push({ BINNO: Bin.BINNO.toString().trim(), QTY: Bin.QTY });
});
Rupesh KahaneRank #136 · 16.4K reputationPosted Nov 4, 2023, 11:18 PM EDT
please check below code for your reference
public void UploadData(dynamic e)
{
this.tableData = null;
this.tableTitle = null;
this.tableRecords = new List
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 5, 2023, 1:15 AM EDT
Hello Ahemad Salah,
Please refer below code in C#,
public void UploadData(object e) { tableData = null; tableTitle = null; tableRecords = new List(); totalPageCount = 0; dataService.StockList = null; var target = (DataTransfer)e; if (target.files.Length != 1) { throw new Exception("Cannot use multiple files"); } var reader = new System.IO.StreamReader(target.files[0]); var binarystr = reader.ReadToEnd(); var wb = new XLSX.WorkBook(); wb = XLSX.Read(binarystr, new { type = "binary" }); var wsname = wb.SheetNames[0]; var ws = wb.Sheets[wsname]; var data = XLSX.utils.sheet_to_json(ws); Console.WriteLine(data); string lengthErr = ""; string qtyErr = ""; data.ForEach(element => { Console.WriteLine(element); var Bin = element; if (Bin.BINNO.ToString().Trim().Length != 9) { lengthErr = element.BINNO; } if (Bin.QTY >= 10) { qtyErr = element.BINNO; } dataService.StockList.Add(new StockLabelList { BINNO = Bin.BINNO.ToString().Trim(), QTY = Bin.QTY }); }); }