What is difference between web.config and app.config files in .Net Applications

What is difference between web.config and app.config files in .Net Applications

Introduction:

In this article i will explain what are the differences between web.config and app.config files. What information can we able to store in this configuration files.

Description:

In previous articles I explained validate email address using  Dropdownlist validation in Asp.net Using RequiredField validator  In ASP.Net And Many Article Relating to Validation Now I Will   Explained  differences between web.config and app.config files  In Asp.net.

These configuration files xml files that can be changed as need by developer. We can say these files are settings files or global files for our applications. Generally these files contains application settings which needs to be available for all of forms in our application. We could store some globally required information here. If we want to use or interact with these files we have to import namespace called System.Configuration(Windows) and System.Web.Configuration(web). Different types of configuration files available in .Net. You can find it in MSDN.


Web.Config:

Web.Config files are purely for web applications.
This file is automatically created when we create new web projects.
we can have many web.config files in web project where each folder can contain single web.config file only.
In this files we can able to store global information which can be accessed based on location of the
config file. Whenever we change these file automatically website will restart with modified details.


App.Config:

App.Config files are for Windows Application.
This file is not add by default when we create new project. We need to externally add these to file to our project by Right Clicking on project --> Select Add New Item--> Select "Application Configuration file".
Modifying App.Config file will not affect the running application until we restart the application.Only one app.config file is allowed in one project.

Conclusion:

Web.Config and App.Config are used for storing global application settings.Check these NameSpaces for more details.System.Configuration(Windows) and System.Web.Configuration(web).


Dropdownlist validation in Asp.net Using Required field validator

Dropdownlist validation in Asp.net Using Required field validator

Introduction:
Here I will explain how to Dropdownlist validation in Asp.net Using Required field validator.
In previous articles I explained validate email address using  code for validating checkbox in asp.net  In 
ASP.Net And Many Article Relating to Validation Now I Will   Explained  Dropdownlist validation in Asp.net Using RequiredField validator  In Asp.net.
To implement this one we need to write code as shown below in your aspx page
<asp:DropDownList  CssClass="dropdown" ValidationGroup="g1" 
ID="dropdown" runat="server" OnSelectedIndexChanged="dropdown_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="dropdown" ID="RequiredFieldValidator1"
ValidationGroup="g1" CssClass="dropdown" ErrorMessage="Select Dropdown"InitialValue="--Select Asprockers--" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>


dropdown.Items.Insert(0, "--Select Asprockers--"));
Code for Validating Checkbox in asp.net with required field validator

Code for Validating Checkbox in asp.net with required field validator

Above I have placed an ASP.Net Custom Validator besides the ASP.Net Checkbox control. For the ASP.Net Custom Validator I have specified the ClientValidationFunction property to a JavaScript function ValidateCheckBox which validates the whether the checkbox is checked or not.


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type = "text/javascript">
function ValidateCheckBox(sender, args) {
if (document.getElementById("<%=CheckBox1.ClientID %>").checked == true) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required" ClientValidationFunction = "ValidateCheckBox"></asp:CustomValidator><br />
<asp:Button ID="Button1" runat="server" Text="Submit"/>
</form>
</body>
</html>
Get (Read) Connectionstring from App.Config File in C#

Get (Read) Connectionstring from App.Config File in C#

Introduction:

Here I will explain how to read or get connectionstring from app.config file in 
c#. By using System.Configuration reference we can read or get connectionstring from app.config file in windows or console application in c#.



<connectionStrings>
<add name="dbconnection" connectionString="DataSource=KaushikDhameliya;Initial Catalog=Kaushik;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

string admin= ConfigurationManager.ConnectionStrings["admin"].ConnectionString;
Get (Read) Connectionstring from App.Config File in C#

Get (Read) Connectionstring from App.Config File in C#



Introduction:

Here I will explain how to read or get connectionstring from app.config file in 
c#. By using System.Configuration reference we can read or get connectionstring from app.config file in windows or console application in c#.



<connectionStrings>
<add name="dbconnection" connectionString="DataSource=KaushikDhameliya;Initial Catalog=Kaushik;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

string admin= ConfigurationManager.ConnectionStrings["admin"].ConnectionString;

Popular Posts