Posts

Showing posts from 2019

HTML string as a JSON output using C#

 var temp = "\\";  string messageEmail = "Dear Sir, <br/><br/><span style="+ temp + "\"font-size:11pt" + temp + "\"> TRANSACTION_ID <b>  " + TNX_CODE + " </b> has been rejected by " + Session["USER_NAME"].ToString() + "</span >  ." + "<span style=" + temp + "\"font-size:11pt" + temp + "\"> </span><br/> Regards, <br/>BVSERT<br/>"; https://stackoverflow.com/questions/48002499/html-string-as-a-json-output-using-c-sharp

C# - Strong Password Regular Expression

^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@ #$%^&*_+=[{\]};:<>|.?,-]).{6,20}$ var hasMatchPasswordRegex = new Regex(service.GetGlobalSetUp().Rows[ 0 ][ "password_regex" ].ToString());             if (!hasMatchPasswordRegex.IsMatch(change_password.NEW_PASSWORD))             {                 response.status = HttpStatusCode.InternalServerError;                 response.statusText = " <strong>Fail</strong>" + service.GetGlobalSetUp().Rows[ 0 ][ "password_mis_match_message" ].ToString();                 var resultOutput = JsonConvert.SerializeObject(response, Formatting.Indented,                       new JsonSerializerSettings                       {   ...

Backup and Restore a PostgreSQL Database

Backup : Backup database in .sql file and with role from dropdown Restore : C:\Program Files\PostgreSQL\ 9.4 \bin>psql -U postgres db_cpm <C:\CPM\cpm.sql

Call rest api using RestSharp C#

try {           string postData = "{\"appnsid\": \"TEST12347\",\"pDEode\":\"007\", \"codecr\":\"0031\", \"tnocr\":\"12200243\",\"amount\":\"1\", \"narration\":\"testing using postman\"}" ;          var client = new RestClient( "http://182.13.9.934" );          client.Authenticator = new HttpBasicAuthenticator( "username" , "password" );          var request = new RestRequest( "ums12c/transactionfrom" , Method.POST);          request.AddHeader( "Accept" , "application/json" );          request.AddParameter( "application/json" ,(postData), ParameterType.RequestBody);          IRestResponse response = client.Execute(request);          var content = response.Content;  }  catch(Exception ex){   string value = ex.Message; }

Microsoft Access Connectivity from C#

<configuration>   <appSettings> <add key= "ConnectionString" value= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BCI.accdb;" /> <add key= "ClientSettingsProvider.ServiceUri" value= "" />   </appSettings> </configuration>

Image file upload in a selected folder in C#

protected void LinkButton1_Click(object sender, EventArgs e) {     string filePath = "" ;     if (fileUpload.HasFile)     {         if (CheckFileType())         {             string postedLogo = fileUpload.PostedFile.FileName.ToString();             string fileName = postedLogo.Split( new char [] { '\\' }).Last();             string fileExtension = fileUpload.PostedFile.FileName.Split( new char [] { '.' }).Last().ToLower();             filePath = "~/MemberPhoto/" + fileUpload.FileName.Replace(fileName, Session[ "UserId" ].ToString() + "." + fileExtension);             try             {                 System.Drawing.Image UploadedImage = System.Drawing.Image.FromStr...

Read from excel and insert into data table in c#

using System.Data.OleDb; using System.IO;   private DataTable ReadExcelToTable ( string path ) {         //Connection String         string extenstion = Path.GetExtension(path);         string connstring = "" ;         if (extenstion == "xls" || extenstion == "XLS" )         {             connstring = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';" ;         }         else         {             connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';" ;         }         //connstring = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO...