Posts

Showing posts from June, 2021

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...

Inserting Third Party Video (You Tube) in Grid View

1. The first way of Embedding the video-  Inorder to Embed the video[You Tube's] in Grid View , the following steps to be followed- i.  Create a template field in Grid View ii. Go to source insert the copied <iframe> of video (you want to embed from you tube ) inside the <ItemTemplate>    iii. Now, your Grid View will be showing the videos.  2. The second way of Embedding the video using database- Inorder to do so just follow simple steps- i. Go to You Tube > start the desired video you want to embed. ii. Copy the id of that video from the URL  https://www.youtube.com/watch?v= that_section Copy the id which will be shown after the '=' sign  iii. And just paste it to the database column.  3. Third way of Embedding the video by TextBox through the user input-   With the help of Eval() this embedding can be done. Steps- 1. Go to source 2. P aste the <iframe> inside <ItemTemplate>. 3. Find the video_url/src attrib...