label control not displaying the text on production server. It works fine in development - label

<asp:Label ID="lblWarehouse" runat="server" Text="" CssClass="lbl" Visible="true"></asp:Label>
lblImagePath.Text = getWarehouse(strImgPath);
private string getWarehouse(string ImgPath)
{
String strPath = "";
String strfolderPath = "";
int intFolderNo = 0;
for (int i = 0; i < 50; i++)
{
intFolderNo = i + 1;
// Begin Change by Triveni Gadipalli on 02/03/2014.
//strfolderPath = #"\\\\\\\\CHC29\Warehouse" + intFolderNo.ToString() + "\\\\" + ImgPath+ "\\\\";
String FolderNo = intFolderNo.ToString();
if (intFolderNo < 10)
{
FolderNo = "0" + FolderNo;
}
strfolderPath = #"\\\\\\\\\\pnasxl40001.chcpa.loc\emrscans\wh" + FolderNo + "\\\\" + ImgPath + "\\\\";
// strfolderPath = #"\\\\\\\\pnasxl40001.chcpa.loc\emrscans\wh" + folderno + "\\\\" + ImgPath + "\\\\";
//End Change by Triveni Gadipalli on 02/03/2014.
if (Directory.Exists(strfolderPath))
{
strPath = strfolderPath;
i = 50;
}
}
if (strPath == "")
{
return strfolderPath;
}
else
{
return strPath;
}
}

Shouldn't the line:
lblImagePath.Text = getWarehouse(strImgPath);
reference lblWarehouse - that's the only label in your example code at least?

Related

HTTPContext.Request Method Equivalent in .Net 6

We used to write code in .Net Framework for DataTable filtering on server side.
This was the old code where HttpContext.Request was working fine. Now in .Net 6 how we can establish the same search and get HttpContext as well in any controller or model class from jquery.
This function is static and I am stuck in HttpContext.Request line where this is throwing exception "Httpcontext does not exist" even if we use IHttpContextAccessor here. How can we access that variable as that is defined in Program.cs.
public static DataTable FilterTable(DataTable dt, ref int Fcount, JQPM p)
{
p.sColumnslist = p.sColumns.Split(',');
string Fstring = ""; Int32 intVal = 0;
if (!string.IsNullOrEmpty(p.sSearch))
{
string[] Arr = p.sSearch.Trim().Split(' ');
for (int i = 0; i < Arr.Length; i++)
{
if (Arr[i] != "")
{
Fstring = "0=1 ";
for (int j = 0; j < p.sColumnslist.Length; j++)
{
if (Convert.ToBoolean(System.Web.HttpContext.Request["bSearchable_" + j]))
{
if (dt.Columns[p.sColumnslist[j]].DataType.Name == "String")
{
Fstring += " or " + p.sColumnslist[j] + " LIKE '%" + Arr[i] + "%'";
}
else if (dt.Columns[p.sColumnslist[j]].DataType.Name == "DateTime")
{
Fstring += " or " + p.sColumnslist[j] + "Format LIKE '%" + Arr[i] + "%'";
}
else
{
if (Int32.TryParse(Arr[i], out intVal))
{
Fstring += " or " + p.sColumnslist[j] + " = " + intVal;
}
}
}
}
//Fstring += " PartyName LIKE '%" + Arr[i] + "%'";
//if (Int32.TryParse(Arr[i], out intVal))
//{
// Fstring += " or SaleVoucherNo = " + intVal;
//}
//Fstring += " or SaleDateFormat LIKE '%" + Arr[i] + "%'";
//dt = GetDatatable(dt, Fstring, ref Fcount, p); Fstring = "";
dt = SearchDatatable(dt, Fstring, ref Fcount, p); Fstring = "";
}
}
}
//else
//{
//dt = GetDatatable(dt, Fstring, ref Fcount, p);
dt = GetDatatable(dt, ref Fcount, p);
//}
return dt;
}
System.Web.HttpContext has changed to Microsoft.AspNetCore.Http.HttpContext; you will need to pass the instance of this from where HttpContext is available into this function.
public static DataTable FilterTable(DataTable dt, ref int Fcount, JQPM p)
becomes
public static DataTable FilterTable(Microsoft.AspNetCore.Http.HttpContext httpContext, DataTable dt, ref int Fcount, JQPM p)
If you are retrieving "bSearchable_" + j from the QueryString and it will only contain that key once you can then use
httpContext.Request.Query["bSearchable_" + j].ToString();
where httpContext is the instance you pass in.
See:
https://learn.microsoft.com/en-us/aspnet/core/migration/http-modules?view=aspnetcore-6.0#migrating-to-the-new-httpcontext
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-6.0

how to restrict double extension while uploading file to server

fileName = inputParam.file_name.split('.')[0].toLowerCase().replace(/ /g, '') + '' + Date.now() + "." + (fileData.file.name.split('.')[1] || inputParam.file_name.split('.')[1])
filePath = filePath + fileName
This is the condition I am using.
For example it should only restrict a.jpeg.jpg or a.php.jpeg. and allow extension like a.a.jpeg or bird.tree.jpeg
var _validFilejpeg = [".jpeg", ".jpg", ".bmp", ".png",".pdf", ".txt"];
var invalid = [".php",".php5", ".pht", ".phtml", ".shtml", ".asa", ".cer", ".asax", ".swf",".xap"];
function validateForSize(oInput, minSize, maxSizejpeg) {
//if there is a need of specifying any other type, just add that particular type in var _validFilejpeg
if (oInput.type == "file") {
var sFileName = oInput.value;
var file = sFileName.match(/\d/g);
var fileExt = sFileName.substr(sFileName.length-4);
if (sFileName.length > 0) {
var blnValid = false;
for (var j = 0; j < _validFilejpeg.length; j++) {
var sCurExtension = _validFilejpeg[j];
if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length)
.toLowerCase() == sCurExtension.toLowerCase()) {
blnValid = true;
break;
}
}
if(fileExt = 'invalid'){
alert("Your document does not have a proper file extension.")
blnValid = false;
}
if(fileExt = 'file'){
alert("Your document does not have a proper file extension.")
blnValid = false;
}
if (!blnValid) {
alert("Sorry, this file is invalid, allowed extension is: " + _validFilejpeg.join(", "));
oInput.value = "";
return false;
}
}
}
fileSizeValidatejpeg(oInput, minSize, maxSizejpeg);
}
function fileSizeValidatejpeg(fdata, minSize, maxSizejpeg) {
if (fdata.files && fdata.files[0]) {
var fsize = fdata.files[0].size /1024; //The files property of an input element returns a FileList. fdata is an input element,fdata.files[0] returns a File object at the index 0.
//alert(fsize)
if (fsize > maxSizejpeg || fsize < minSize) {
alert('This file size is: ' + fsize.toFixed(2) +
"KB. Files should be in " + (minSize) + " to " + (maxSizejpeg) + " KB ");
fdata.value = ""; //so that the file name is not displayed on the side of the choose file button
return false;
} else {
console.log("");
}
}
}
<input type="file" onchange="validateForSize(this,20,5000);" >
You can simply do this
if (fileName.split('.').length > 2) {
throw new Error('Double extension file detected')
}

Error when accessing Persistant vector of object instances

My Near contact contract returns an error when I attempt to access a Persistent vector of object instances in the listcourses function.
Log [dev-1642726071766-23690329778292]: ABORT: Cannot parse JSON, filename: "~lib/assemblyscript-json/decoder.ts" line: 144 col: 5
Failure [dev-1642726071766-23690329778292]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: Cannot parse JSON, filename: \"~lib/assemblyscript-json/decoder.ts\" line: 144 col: 5"}}
ServerTransactionError: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: Cannot parse JSON, filename: \"~lib/assemblyscript-json/decoder.ts\" line: 144 col: 5"}}
at Object.parseResultError (/home/jjsullivan/.nvm/versions/node/v17.2.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/rpc_errors.js:31:29)
at Account.signAndSendTransactionV2 (/home/jjsullivan/.nvm/versions/node/v17.2.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:160:36)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async scheduleFunctionCall (/home/jjsullivan/.nvm/versions/node/v17.2.0/lib/node_modules/near-cli/commands/call.js:57:38)
at async Object.handler (/home/jjsullivan/.nvm/versions/node/v17.2.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
type: 'FunctionCallError',
import { storage, context, PersistentVector } from "near-sdk-as";
import { Course } from "./course";
// return the string 'hello world'
export function helloWorld(): string {
return 'hello world and \r\ngreetings earthlings from the Blockchain Academy'
}
export function welcomeUser(): string {
return "Greetings " + context.sender + " .... :)"
}
let studentlist = new PersistentVector<string>('student');
let absentlist = new PersistentVector<string>('absent');
let roster = new PersistentVector<string>('list');
let courselist = new PersistentVector<Course>('courses');
#mutateState()
export function initial(): string{
if(roster.length < 1 ){
//let courselist = new PersistentVector<Course>('courses');
let slist = new Array<string>();
let courseqty = new Array<Course>();
let scount: i32 = 0;
let strstuds: string = "";
let course0 = new Course(101, "Java", true);
let crs: string = "";
courselist.push(course0);
let courseamt: i32 = 0;
slist[0] = "Rob Sims";
scount++;
slist[1] = "Mike Dorgan";
scount++;
slist[2] = "Tom Reager";
scount++;
slist[3] = "Mary Smith";
scount++;
slist[4] = "Ryan Williams";
scount++;
slist[5] = "Bryant Nielson";
scount++;
slist[6] = "Ryan Kraz";
scount++;
for(let j = 0; j < scount; j++){
studentlist.push(slist[j]);
roster.push(slist[j]);
const mystudent = slist[j];
strstuds = strstuds + " " + j.toString() + ": " + mystudent + ", ";
}
courseamt = courselist.length;
strstuds = strstuds + " \nThere is " + courseamt.toString() + " course. The course is: " + course0.get_coursename();
return strstuds;
}else {
return "Students may be initialized.";
}
}
export function markabsent(studentnum: i32): string {
if(studentlist.containsIndex(studentnum)){
let abstudent: string = "";
abstudent = studentlist[studentnum];
studentlist.swap_remove(studentnum);
absentlist.push(abstudent);
return "Student " + abstudent + " marked absent.";
}
return "ok";
}
export function listabsent(): Array<string> {
let abstudlist = new Array<string>();
let indx = new Array<i32>();
let i: i32 = 0;
while (i < absentlist.length){
indx[i] = i;
abstudlist.push(indx[i].toString() + " : " + absentlist[i]);
i++;
}
return abstudlist;
}
export function addStudent(student: string): string{
let mystudent: string = "";
mystudent = student;
studentlist.push(mystudent);
roster.push(mystudent);
return "Student " + mystudent + " added. There are now " + studentlist.length.toString() + " students.";
}
export function removeStudent(rmstud: string): string{
let ablist = new Array<string>();
let studlist = new Array<string>();
let rmstudent: string = "";
let abstudent: string = "";
let stud: string = "";
let abindx = new Array<i32>();
let absentidx: i32;
//let ridx = new Array<i32>();
//let abidx = new Array<i32>();
let x: i32 = 0;
let y: i32 = 0;
while (y < studentlist.length){
//ridx[y] = y;
stud = studentlist[y];
if(stud == rmstud){
rmstudent = studentlist.swap_remove(y);
}
y++;
}
while (x < absentlist.length){
abstudent = absentlist[x];
if(abstudent == rmstud){
rmstudent = absentlist.swap_remove(x);
}
x++;
}
return "Removed " + rmstudent;
}
export function listStudents(): Array<string>{
let studlist = new Array<string>();
let indx = new Array<i32>();
let i: i32 = 0;
//
while (i < studentlist.length){
indx[i] = i;
studlist.push(indx[i].toString() + " : " + studentlist[i]);
i++;
}
return studlist;
}
export function movePresent(abstudnum: i32): string {
if(absentlist.containsIndex(abstudnum)){
let abstudent: string = "";
abstudent = absentlist[abstudnum];
absentlist.swap_remove(abstudnum);
studentlist.push(abstudent);
return "Student " + abstudent + " moved from absent tp present.";
}else {
return "Cannot find student with index " + abstudnum.toString() + ".";
}
}
export function addCourse(id: i32, cnm: string, offered: boolean): string{
let id0: i32 = 0;
let cnm0: string = "";
let offered0: boolean;
let clist: string = "";
id0 = id;
cnm0 = cnm;
offered0 = offered;
let len: i32 = 0;
len = courselist.length;
let newcourse = new Course(id0, cnm0, offered0);
courselist.push(newcourse);
len = courselist.length;
let addedcourse: string = "";
let courseid: i32 = 0;
let mycrs_name: string = "";
let noffered: boolean;
courseid = newcourse.get_coursenum();
mycrs_name = newcourse.get_coursename();
noffered = newcourse.get_offered();
//const thecourse = courselist[id];
addedcourse = "Added course. ID: " + courseid.toString() + " Name: " + newcourse.get_coursename() + " Offered: " + noffered.toString();
addedcourse = addedcourse + ". The course list length: " + len.toString();
return addedcourse;
}
#mutateState()
export function listcourses(): string{
let clist = new Array<Course>();
let z: i32 = 0;
let coursedata: string = "";
let myid: i32 = 0;
let mycname: string = "";
let myoffered: boolean;
//let courseinfo: Course;
while (z < courselist.length){
clist.push(courselist[z]);
coursedata = coursedata + " " + myid.toString() + " "+ mycname;
z++;
}
return coursedata + " " + z.toString();
}
Class code
//#nearBindgen
export class Course {
private coursenum: i32
private cname: string;
private offered: boolean;
constructor (coursenum: i32, cname: string, offered: boolean) {
this.cname = cname;
this.coursenum = coursenum;
this.offered = offered;
}
set_coursenum(): void {
this.coursenum = coursenum;
}
set_coursename(): void {
this.cname = cname;
}
set_offered(): void {
this.offered = true;
}
set_notoffered(): void {
this.offered = false;
}
get_coursenum(): i32 {
return this.coursenum;
}
get_coursename(): string {
return this.cname;
}
get_offered(): boolean {
return this.offered;
}
}
You have to enable the #nearBindgen annotation in your class.
It looks like it's commented out in the top of your class code. Remove the first two slashes "//" before // #nearBindgen.
That way, you're able to serialize and deserialize the class to and from JSON
#nearBindgen // remove the "//"
export class Course {
...
}

Ajax request fails in JBOSS EAP 7.1 in Java EAR application

I've EAR applications which run fine in JBOSS EAP 6.3. When I run this application in EAP 7, then ajax call response is empty after few call. Mainly jsp page calls servlet using ajax. I use common code snippet for AJAX call. I can get response properly first 3/4 times. After that it is not working. The whole thing is working fine in EAP 6.3.
The ajax code snippet is as follows:
try{
objXMLHTTP = new XMLHttpRequest();
}catch(e){
try {
objXMLHTTP = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(e){
try {
objXMLHTTP = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e) {
try {
objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
alert("XMLHTTP Not Supported On Your Browser");
return;
}
}
}
}
var urlstr = "" ;
var key = "";
var j = 0;
//dataStore is an array of key/value pair.
for(key in dataStore){
if(j == 0) {
urlstr += key + "=" + dataStore[key];
j = 1;
} else {
urlstr += "&" + key + "=" + dataStore[key];
}
}
var _dateTime = new Date().getTime();
urlstr += "&CALLTIME=" + _dateTime + "-";
var requNumber = "?requNumber=" + _dateTime;
// http request has been changed as Parameterised
var _AsyncRequest = true;
try{
if(_httpMode == "undefined")
_httpMode = "0";
}catch(e){
_httpMode = "0";
}
if((_httpMode != "undefined") && (_httpMode != null) && (_httpMode == "1"))
{
_AsyncRequest = false;
}
if(!document.all)
{
_AsyncRequest = false;
}
if(urlstr.length<=1000) {
objXMLHTTP.open("POST","XMLDHTTPServlet" + requNumber + "&" + urlstr,false);
} else {
objXMLHTTP.open("POST","XMLDHTTPServlet" + requNumber,false);
}
urlstr = URLEncode(urlstr);
objXMLHTTP.setRequestHeader("content-type", "application/x-www-form-urlencoded") ;
//The following is not working after few calls
if(urlstr.length<=1000) {
objXMLHTTP.send("");
} else {
objXMLHTTP.send(urlstr);
}
rtnXML = objXMLHTTP.responseText;
if (objXMLHTTP.statusText == "OK" )
// This condition fails after successive requests
{
//Code
}
Following is in JSP page to call the AJAX. Most importantly, when I put the character **|**, then response in empty and objXMLHTTP.statusText shows Bad Request in EAP 7. But EAP 6, it is working fine.
var objXMLApplet = new xmlHTTPValidator();
objXMLApplet.clearMap();
objXMLApplet.setValue("Package", "panaceaFLweb.getMenuInfo.ReadInfo");
objXMLApplet.setValue("ValidateToken","true");
objXMLApplet.setValue("Method", "chkEODStatus");
objXMLApplet.setValue("BRNCH_CODE",BranCode);
objXMLApplet.setValue("CURR_BUSS_DATE",CBD);
objXMLApplet.setValue("DataTypes","S|S");
objXMLApplet.sendAndReceive();
It is because character | present in URL post request and didn't encode the string which length is less than 1000. Just use
urlstr = URLEncode(urlstr);
before if/else condition of connection open.
Code snippet are as follows:
urlstr = URLEncode(urlstr);
if(urlstr.length<=1000) {
objXMLHTTP.open("POST","XMLDHTTPServlet" + requNumber + "&" + urlstr,false);
} else {
objXMLHTTP.open("POST","XMLDHTTPServlet" + requNumber,false);
}
objXMLHTTP.setRequestHeader("content-type", "application/x-www-form-urlencoded") ;
if(urlstr.length<=1000) {
objXMLHTTP.send("");
} else {
objXMLHTTP.send(urlstr);
}
rtnXML = objXMLHTTP.responseText;
And URLEncode function definition are as follows:
function URLEncode(urlstr ){
var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()=?&";
var HEX = "0123456789ABCDEF";
var plaintext = urlstr;
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " "){
encoded += "+";
}else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
}else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
encoded += "+";
}else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
}
return encoded;
}

format export to excel using closedxml with Title

I am exporting to excel using closedxml my code is working fine, but i want to format my exported excel file with a title, backgroundcolour for the title if possible adding image.
private void button4_Click(object sender, EventArgs e)
{
string svFileName = GetSaveFileName(Convert.ToInt32(comboBox1.SelectedValue));
DataTable dt = new DataTable();
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
dt.Columns.Add(col.HeaderText);
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataRow dRow = dt.NewRow();
foreach (DataGridViewCell cell in row.Cells)
{
dRow[cell.ColumnIndex] = cell.Value;
}
dt.Rows.Add(dRow);
}
//if (!Directory.Exists(folderPath))
//{
// Directory.CreateDirectory(folderPath);
//}
if (svFileName == string.Empty)
{
DateTime mydatetime = new DateTime();
SaveFileDialog objSaveFile = new SaveFileDialog();
objSaveFile.FileName = "" + comboBox1.SelectedValue.ToString() + "_" + mydatetime.ToString("ddMMyyhhmmss") + ".xlsx";
objSaveFile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
objSaveFile.FilterIndex = 2;
objSaveFile.RestoreDirectory = true;
string folderpath = string.Empty;
Cursor.Current = Cursors.WaitCursor;
if (objSaveFile.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
FileInfo fi = new FileInfo(objSaveFile.FileName);
folderpath = fi.DirectoryName;
int rowcount = 0;
int sheetcount = 1;
int temprowcount = 0;
using (XLWorkbook wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add(dt,comboBox1.Text.ToString() + sheetcount.ToString());
ws.Row(1).Height=50;
//ws.FirstRow().Merge();
ws.Row(1).Merge();
//ws.Row(1).Value = comboBox1.Text.ToString();
//ws.Row(1).Cell(1).im
ws.Row(1).Cell(1).Value = comboBox1.Text.ToString();
ws.Row(1).Cell(1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
ws.Row(1).Cell(1).Style.Alignment.Vertical=XLAlignmentVerticalValues.Center;
ws.Row(1).Cell(1).Style.Fill.BackgroundColor = XLColor.Red;
ws.Row(1).Cell(1).Style.Font.FontColor = XLColor.White;
ws.Row(1).Cell(1).Style.Font.FontSize = 21;
ws.Row(1).Cell(1).Style.Font.Bold = true;
ws.Column(1).Merge();
ws.Column(1).Style.Fill.BackgroundColor = XLColor.Red;
ws.Cell(2, 2).InsertTable(dt);
wb.SaveAs(fi.ToString());
//wb.SaveAs(folderpath + "\\" + comboBox1.SelectedItem.ToString() + "_" + mydatetime.ToString("ddMMyyhhmmss") + ".xlsx");
//rowcount = 0;
//sheetcount++;
//}
}
//}
MessageBox.Show("Report (.xlxs) Saved Successfully.");
}
}
else
{
Cursor.Current = Cursors.WaitCursor;
string folderpath = string.Empty;
folderpath = Properties.Settings.Default.ODRSPath + "\\" + svFileName;
using (XLWorkbook wb = new XLWorkbook())
{
//DateTime mydatetime = new DateTime();
wb.Worksheets.Add(dt, comboBox1.SelectedItem.ToString());
wb.SaveAs(folderpath);
}
MessageBox.Show("Report (.xlxs) Saved Successfully.");
}
}

Resources