Posts

Extension Methods

CAMEL CASING  using System; using System.Linq; namespace TestProject {     public static class StringExtensions     {         public static string ToCamelCase(this string value)         {             string[] strings = value.Split(' ');             var capitalisedText = strings[0].Substring(0, 1).ToLower() + strings[0].Substring(1).ToLower();             for (int i = 1; i < strings.Count(); i++)             {                 capitalisedText += strings[i].Substring(0, 1).ToUpper() + strings[i].Substring(1).ToLower();             }             return capitalisedText;         }     }     internal class Program     {         static vo...

Redis Cache Implementation

PRE-REQUISITES:- 1.)  Install Redis For Local using Below Link:-  https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.msi 2.) Redis access for a particular port in Local:- i.e, 127.0.0.1:6379 3.) Configure Redis and Start using the service.  CODE:- [Route("api/[controller]")] [ApiController] public class SearchController : ControllerBase {     private readonly ConnectionMultiplexer _redis;     private readonly IConfiguration _configuration;     private readonly EmailSettings _emailSettings;     public SearchController(IConfiguration configuration, IOptions<EmailSettings> emailSettings)     {         _redis = ConnectionMultiplexer.Connect(configuration["RedisDb"]);         _configuration = configuration;         _emailSettings = emailSettings.Value;     }     [HttpPost("get-search-history-by-word")] ...

Audio to Text Detection

  [HttpPost("convertBase64ToText")] public IActionResult ConvertBase64ToText([FromBody] string base64Audio) {     try     {         // Decode Base64 to raw audio data         byte[] audioBytes = Convert.FromBase64String(base64Audio);         string text = "";         if (IsMp3HeaderPresent(audioBytes))         {             byte[] wavData = ConvertMp3ToWav(audioBytes);             text = RecognizeSpeech(wavData);         }         else if (IsWavHeaderPresent(audioBytes))         {             text = RecognizeSpeech(audioBytes);         }         else          {             return BadRequest("File Format is Not Supported"); ...

Grid View Paging

  Grid View paging- Grid view paging is used when we have to read the data in bulk then we divide the complete data records into pages consists 10 records in one page. SqlDataAdapter - It is used for Grid View Paging Data Adapter reads data in group of 10 records unlike DataReader which reads the data line by line. DataSet - DataSet Object is created, it accepts the data in bulk. Fill() - Fill() is used. CODE - protected void display() { //Connection Code string s = ConfigurationManager.AppSettings["db"]; cn = new SqlConnection(s); cn.Open(); //DataSet Object DataSet ds = new DataSet(); string s = "select * from Videodb"; //SqlDataAdapter object SqlDataReader adp = new SqlDataAdapter(); adp.Fill(ds); GridView1.DataSoruce = ds; GridView1.DataBind(); } Source code-   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"              Height="589px" Width="483px" OnPageIndexChanging="click...

UnEditable TextBox (For Security)

   <asp:TextBox ID="someId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false" Text="hi"></asp:TextBox> Note:- A textbox will be appeared in the screen on which you can not do any operation wheather  it is to copy the data , cut the data, paste the data and delete the data  - this is used for security purposes.

Sending Image Through Mail in dot net

Method 1: Sending mail by directly giving the link in src:- protected void mail_send(object sender, EventArgs e)     {         connectdb();         string q = "select img from wedding_regdb where userid='" + TextBox1.Text + "'";         cm = new SqlCommand(q, cn);         dr = cm.ExecuteReader();         if (dr.Read())         {                          GridViewRow gr1 = ((Button)sender).NamingContainer as GridViewRow;             Button b2 = (Button)gr1.FindControl("mailbtn");             SmtpClient sm = new SmtpClient("student-cell.com", 25);             sm.Credentials = new System.Net.NetworkCredential("contact@student-cell.com", "password");             sm.DeliveryMethod =...

API for whatsapp

        Response.Redirect("https://api.whatsapp.com/send?phone=+91" + TextBox1.Text + "&text=" + TextBox2.Text);

Final Project

Image
Registration form project   CODING- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; public partial class RegPage : System.Web.UI.Page {     SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     FinalClass fc = new FinalClass();     protected void Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {             statedisplay();         }     }     protected void connect()     {         string s = ConfigurationManager.AppSettings["Ch_Db"];         cn = new SqlConnection(s);         cn.Open();          }     protected void statedisplay...

Checking File Extension

                   string ext = System.IO.Path.GetExtension(FileUpload1.FileName);         if (ext != ".jpg" && ext != ".jpeg")         {             Response.Write("accept only jpg file");         }         else         {              FileUpload1.SaveAs(Server.MapPath("~") + "//upload//" + FileUpload1.FileName);             Image1.ImageUrl = "~/upload/" +  FileUpload1.FileName;                 }

Export GridView to Excel

            string attachment = "attachment; filename=registration.xls";         Response.ClearContent();         Response.AddHeader("content-disposition", attachment);         Response.ContentType = "application/ms-excel";         StringWriter sw = new StringWriter();         HtmlTextWriter htw = new HtmlTextWriter(sw);         HttpContext.Current.Response.Write("<br>");         HtmlForm frm = new HtmlForm();         GridView1.Parent.Controls.Add(frm);         frm.Attributes["runat"] = "serve";         frm.Controls.Add(GridView1);         frm.RenderControl(htw);         Response.Write(sw.ToString());         Response.End();

Dynamic Data Grid View

protected void Button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3]  { // typeof() is used for dynamic data type allocation new Column("id",typeof(int)), new Column("Name",typeof(string)), new Column("City",typeof(string)) }); dt.Rows.Add(1,"Chitransh","Jabalpur"); dt.Rows.Add(2,"Shashank","Bhopal"); dt.Rows.Add(3,"Ananya","Delhi"); GridView1.Datasource = dt; GridView1.DataBind(); }

Select the RadioButtonList Item Using User Input

  CODE:- RadioButtonList1.Items.FindByText(dr["column_name"].ToString()).Selected== true; --------------------------------------------------------------------------------------------------------------------- Implementation:-   protected void Button3_Click(object sender, EventArgs e)     {         myclass m1 = new myclass();         string cs = m1.connection(); // calling function inside a class          cn = new SqlConnection(cs);         cn.Open();         string q = "select * from chitransh_table where name='"+TextBox5.Text+"'";         cm = new SqlCommand(q, cn);         dr = cm.ExecuteReader();         if (dr.Read())         {             RadioButtonList1.Items.FindByText(dr["city"].ToString()).Selected = true;         }   ...

Break the Control Refreshment

  Example:- <form>   <asp:ScriptManager> </asp:ScriptManager> <asp:UpdatePanel> <ContentTemplate> <asp:DropDownList>// place any Drop down list  <asp:ListItem> //Items </asp:ListItem> </asp: DropDownList > </ContentTemplate> </asp:UpdatePanel> </form>

Email Programming

  Email-  It is used to send a message electronically. Types of email- 1. Simple mailing(Gmail,Yahoo) Open to all. 2. Domain Based Email(WebMail) Company uses this kind of mail. Email programming in dot net- Steps-  1. Include library- using System.Net.Mail; 2. Objects are created- i. smtpClient ii. MailMessage  3. Format of email- html  Coding- //Two parameters - domain name and port number of email. smtpClient sm = new smtpClient("student-cell.com",25);  // here we have to give the credentials email id and password  sm.Credentials = new System.Net.NetworkCredential("contact@student-cell.com","password"); //this method will deliver your email to network sm.DeliveryMethod = smtpDeliveryMethod.Network;  // Mail Message object is created passing the email id and the control where recipient id will be  MailMessage mm = new MailMessage("contact@student-cell.com",TextBox1.Text); mm.Subject = "Hey buddy its me" + TextBox1.Text; mm.Body = ...

Repeater

  Repeater is a data control.  It is used to display the controls in repeated manner. Repeater Control Event Handling [Using Eval()] In order to attain Event Handling we have to create two events. 1. Event of repeater's itself- OnItemCommand 2. Event of the control inside the repeater- CommandName Note:- we don't use onClick Event for controls in repeater. ------------------------------------ Format- <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="repeat_click" > <ItemTemplate> <img src='/file_name<%# Eval("column_name") %>' height="100px" width="100px"/>  <asp:Label ID="Label1" runat="server" Text='<%# Eval("column_name")%>'></asp:Label> <asp:Button ID="Btn1" runat="server"  Text="Submit" CommandName="submit_click"  /> </ItemTemplate> </asp:Repeater>  Coding- //C...

Creating Directory using code

  How can we create directory- 1. In order to create a directory we have to first include a library called IO. using System.data.IO; 2. select a TextBox and a Button from toolbox. 3. write the code inside the button- Directory.CreateDirectory(Request.MapPath(Textbox1.Text) + "/"));

System Object[ Displaying all entities and their records ]

Image
  System Object- System Object represents all entities in the data base.  Objective- We have to code inside the Show Entities button such that all entities inside the database will be shown in the List Box below. And By selecting one of the entities the user can also see the records inside the table by clicking on Show records button. Show Entities button code- { string cn = ConfigurationManager.AppSettings["key"]; cn = new SqlConnection(cs); cn.Open();  string q = "select name from sysobjects where xtype='U' order by name"; cm = new SqlCommand(q,cn); dr = cm.ExecuteReader(); ListBox1.DataSource = dr; ListBox1.DataTextField = "name"; ListBox1.DataBind();  dr.Close(); }  Show Records Code-  {   string cn = ConfigurationManager.AppSettings["key"]; cn = new SqlConnection(cs); cn.Open();   string q = "select * from" + " " + ListBox1.Text; cm = new SqlCommand(q,cn);  dr = cm.ExecuteReader;  GridView1.DataSource = dr; Grid...

Parameter Query

If we pass the value with (, ' " ! $) symbols in the control that will not be accepted through normal query. Parameter Query is used to accept the value with special symbols in the control like textbox. Parameter Query use a user defined variable with an @ sign.  In Parameter Query control is written in a different syntax. Column name and variable name can not be the same. Without column_name we can not perform Parameter query. Syntax- Insert- string s= "insert into Table_name (Column_name) values (@variable_name)"; cm = new SqlCommand(s,cn); cm.Parameters.AddWithValue("variable_name", control_name); cm.ExecuteNonQuery(); Update- string q = "update Proc_table set name=@name1 where email = @email1"; cm = new SqlCommand(q, cn); cm.Parameters.AddWithValue("name1", TextBox1.Text); cm.Parameters.AddWithValue("email1", TextBox2.Text); cm.ExecuteNonQuery();  

Data Base Security

  DataBase Security is one of the important parts in web development.  Inorder to maintain that, the vulnerable code like Data base path , query or etc is written inside the Class file in the form of functions and in the needy page they are only called. How to create Class file- Select the root > go to website menu > Add new item >Select class > give a desired name to class(lets say MyClass ) Inside it write the code for Object creation and library inclusion. After that, create the function for each thing- 1. For connection-  public string Connection() { string cs = @"data_base_path"; return cs; }  2. For query- Insert- public string Insertq() {  string q = "insert into Table_name values";  return q; }   Update- public string Updateq() {  string q = "update Table_name set";  return q; }   Select- public string Selectq() {  string q = "select * from Table_name where";  return q; }    Delete- pub...

Configuration Using Connection String

  In order to stay connected with the data base we need to give the database path in each and every page but this becomes tedious when we want to change the ip address of the path. so, this requires changes performed in every single page. To resolve this we can put the data base path in the config file so when the modifications needed we just have to change the path in config file not in each and every page.   web.config-   1. Go to config file. 2. Delete the <ConnectionStrings> tag with the data inside. 3. Insert <AppSettings> in place of <ConnectionStrings> . 4. Inside <AppSettings> insert <add> tag. 5. <add> has two atttributes. i. key - Any key can be assigned[it is user defined] ii. value - the value attribute is contained the path of database(paste the data base path inside the value attribute) .aspx.cs[Code window]-  Include System.configuration library. Connection open code- string cn = ConfigurationManager.AppSet...