Twitter Feed Popout byInfofru

Localization in asp.net (Quick View)

In the past few days, I see some posts in forum (http://www.asp.net) regarding Localization which is actually very easy but there is no quick view to Localization in available. So I plan to write one for my blog.Localization is something by which you can provide your end user a functionality to read your content in multiple languages. To cut it short … you have content in languages as such English and French and you are managing the whole stuff on one page. That is the main concept of Localization.Now, to use the feature of localization asp.net provides you with a file called Resource File (.RESX). Remember the time of Visual Studio 2003 it is added with the page by default. This file is nothing more than a normal XML file having Key / Value pairs stored inside.The Resource files will be created under some special folders which are as follows.App_GlobalResourcesApp_LocalResourcesThe difference between two is visible by their name which is off the scope. The content of Global one is available throughout the website where as the local is limited to that specific page.
Step 1:Create both folders in your project as we will use them in future. To create1. Right click your project2. Then Asp.net Folders3. And select both one by one.
First, we will look into Local Resources. To use the local resources file which is limited to the page level, let’s first decide what we want to do.Scenario: We want to create a login page for two languages English (US) and French.
Step 2:To do this, we need to design a page which looks like as follows (design view). The page name will be defult.aspxsnapshot_lc_1.jpg Source:<br /><asp:Label ID="lblTitle" runat="server" meta:resourcekey="lblTitle"></asp:Label><br /><br /><asp:Label ID="lblUserId" runat="server" meta:resourcekey="lblUserId"></asp:Label><asp:TextBox ID="txtUserId" runat="server" ></asp:TextBox><br /><asp:Label ID="lblPassword" runat="server" meta:resourcekey="lblPassword" ></asp:Label><asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br /><br /><asp:Button ID="btnSubmit" runat="server" meta:resourcekey="btnSubmit"/><asp:Button ID="btnCancel" runat="server" meta:resourcekey="btnCancel" />
 Forget, those bad BR just want to give you the idea how localization work. Notice that we have not set text for any of our control specifically, Button and Labels instead we have one new thing here and that is meta:resourcekey=”btnSubmit”.Forget what it does, just continue with step 3. 
Step 3:1. Right - Click on App_LocalResources2. Click Add New Item3. From the list of template select Resource File4. Name the resource file as default.aspx.resx (because default.aspx is our page name, if it were supercool.aspx the resource file will be supercool.aspx.resx. Remember it is the default resource file for the page.)5. Make it look like following
snapshot_lc_2.jpgNow, you can see the relationship between meta:resourcekey=”btnSubmit” and resource file. Let me make it more easy, Notice the second entry from top. It isbtnSubmit.Text : Submit.It means by writing meta:resourcekey=”btnSubmit” on any control, asp.net runtime will bind all the properties specified in resource file to the that control.Just run the page we have created means default.aspx and you will see the text of all controls extracted from the default resource file. Now let’s create a new resource file for the same page but for different culture.
Step 4:1. Right - Click on App_LocalResources2. Click Add New Item3. From the list of template select Resource File4. Name the resource file as default.aspx.fr-FR.resx (this time we are creating resource file for our page in French. So we specify, the runtime engine understandable culture code. Please bear in mind the fr-FR is only for French to know more like this please visit http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx)5. Now make it look like following
snapshot_lc_3.jpgTo change the culture we need to add the following dropdown at the top of our page.
Step 5:Culture :<asp:DropDownList ID="ddlCulture" runat="server" AutoPostBack="True"><asp:ListItem Text="English" Value="en-US"></asp:ListItem><asp:ListItem Text="French" Value="fr-FR"></asp:ListItem></asp:DropDownList>And following code against this drop down.Protected Sub ddlCulture_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCulture.SelectedIndexChangedSession("Culture") = ddlCulture.SelectedValue 'Storing culture selected in session        Response.Redirect(Request.RawUrl)End Sub
Now, we have created the drop down stuff let’s move on how to set the culture.Step 6: 

Protected Overrides Sub InitializeCulture()

        If Not Session("Culture") = "" Then            Dim selLang As String = Session("Culture")'getting the culture from session                       Page.UICulture = selLang 'setting page culture            Page.Culture = selLang               'Setting thread culture            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selLang)            Thread.CurrentThread.CurrentUICulture = New CultureInfo(selLang)        End If        MyBase.InitializeCulture()End Sub

Note : As you might notice there are two thing we are dealing with one is Culture and the other is CultureUI. Well, Culture is somthing like the Date Time / Currency of the page where is CultureUI is the UI settings for the control such as text and other proerties.
Till here, we have finished with the local resources files. Now let’s move forward and add a new resource file in App_GlobalResource, which is for the global access.
Step 7:1. Right - Click on App_GlobalResource2. Click Add New Item3. From the list of template select Resource File4. Name the resource file as MyGlobalResource.resx. (notice there is no special need for global resources)5. Now make it look like followingsnapshot_lc_4.jpgTo check Global Resources let us write following code on the click of submit button  Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.ClickResponse.Write(GetGlobalResourceObject("MyGlobalResource", "Success_Key")) '"MyGlobalResource" is the name of the classEnd Sub
That’s it, now if you press the submit button you will see the message we store in Global Resource file. Notice that, Global resource files are not culture specific and it is normally used to store things which are similar in all cultures as such images and all that.I have tried to make this post as much simple as I can, but I think it has gone quit long as the topic of Localization is not that easy to cover in 5 lines of post so I m thinking to create a video stuff for this .

Microsoft enterprise Library Data Block

Hey geeks,Well ... It is always difficult to understand someone's code which you have writted already. I have written a Library called Data Aceess Tools, which is more like a data block of enterprise library. However, enterprise library is quit advance then Data Aceess Tools, which make my interest to work on enterprise library. so let me give you step by step instrucion. now please dont ask me to define the installations step thats too simple, we have been doing the same installation from childhood. so lets get down to the business.Step 1 (Adding Enterprise Library to Project):Geeks, before I start I would like to remind again that this article is will provide only Data Block information that is why we need to register two dlls in out project.1) Microsoft.Practices.EnterpriseLibrary.Data.Sql & Microsoft.Practices.EnterpriseLibrary.Data.Yes, It is sure very easy. so lets move on.Step 2 (Coding):first of all import the foloowing libraries in the class
Imports Microsoft.Practices.EnterpriseLibrary.Data.SqlImports Microsoft.Practices.EnterpriseLibrary.Data
Now for creating the connection, Create Database object and pass the connection String in the method.
Dim db As Database = DatabaseFactory.CreateDatabase("Database")
Well in our case we are trying to access Stored procedure, so lets start with that.
Dim DbCommand As Common.DbCommand = db.GetStoredProcCommand(“Sp_writeData“)
now lets add parameters for stored procedure.
db.AddInParameter(DbCommand, "@UserID", DbType.Int32, reportId)db.AddInParameter(DbCommand, "@Age", DbType.Int32, reportJobId)db.AddInParameter(DbCommand, "@MisInfo", DbType.Xml, parameterXml)
Okay let me define these lines. db is the name of database object by which we are adding parameters. DbCommand is the name of command Object in which we are adding parameters.Now if this stored procedure returning you result then do the following:
db.ExecuteScalar(DbCommand)
or
Dim dr as SqlClient.SqlDataReader = db.ExecuteReader(DbCommand)
or
Dim ds as DataSet = db.ExecuteDataSet(DbCommand).
here it is , now you got the result in your recordset ..... do whatever you want to . (with database) :)

Dotnet Interview Question Series 2

Q1)What is View State?

Ans)It contains state of control, which asp.net runtime reloaded when the post back operation occurs.

Q2)Can you read the View State?
Ans) Yes, For Example:
Response.write(viewstate("myname"))

Q3)Can we disable the view state application wide?
Ans) by specifying the followig line in web.config

Q4)Can we disable it on page wide?
Ans)Yes,by specifying Viewstate="false" in page directive.
<% Page viewstate="false"%>

Q5)can we disable it for a control?

Ans)Yes,by specifying Viewstate="false" in control markup.

Q6)Any idea of Enterprise library?

Ans) Heaven, Enterprise Library is a library from Microsoft Patterens & Practices which provide you with the different application block example
Data Access
Security
Logging
Exception
and much more.
It actually gives you classes to implement different re-useable functionalities.

Q7)What is web service?

Ans) We can assume a web service as a method over the web, It actually takes the parameter and give the result in the XML format for independablity.furthermore, It use SOAP formatted XML enavlops and use WSDL for interfacing.

Q8)What is WSDL?

Ans) It is XML based language which provide a model for describing Web Service, meaning that it gives description how to communicate with Web serice. It use in the combination of XML Schema and SOAP.

Q9)Can a web service be only developed in asp.net?

Ans) No, We can also develop webservices using Java (JSP).

Q10)Can we use multiple web services from a single application?

Ans) Yes...

Q11)can we call a web service asynchronously?

Q12)Can a web service be used from a windows application?

Ans) Yes, the speciliaty of windows service is that it can be called from any where, either windows application or mobile application.

Q13)What do we need to deploy a web service?

1.At the command prompt:

WSDL http://ip address ofthe site/WebService/MathService.asmx /n:NameSp /out:FileName.cs]
-This will create a file called FileNmame.cs .

WSDL -> WebServices Description Language (This is an application available at C:\\Program

Files\\Microsoft.NET\\FrameworkSDK\\Bin)

NameSp -> Name of the NameSpace which will be used in client code for deploying the

webservice.

2.Compilation

CSC /t:library /r:system.web.dll /r:system.xml.dll CreatedFile.cs

This will create a dll with the name of the public class of the asmx file.( In our case, it

is "AddNumbers.dll" )

CSC is an application available at C:\\WINNT\\Microsoft.NET\\Framework\\v1.0.2914

3.Put the dll file inside WWWRooT\\BIN [Create a BIN Folder in WWWRoot]

Q14)What is the significance of web.config?

Ans) It is the most significant part of any application, actually it contain the configuration which can be readable for runtime enviroment and manage the application accordingly.

Q15)Can we have multiple web.config files in a sigle web project?

Ans) Sure, we can have as different web.config file in every single folder for example If I want all the pages "/Presentation" reside in this folder use different database, I write another web.config file and put it under "/presentation". furthermore, we have a default web.config file on the root of web application. if any folder doesnot have its own web.config runtime automatically read the default one for configuration. and evenif there
is no default web.config file located it read machine.config to get the configuration syntax

Q16)Can we have more then one configuration file?
Ans) Yes the method will be same as above


Q17)Type of Authentications?

Ans) Windows, Forms, and Passport

Q18)Can we have multiple assemblies in a single web project?

Ans) The default architecture of .net framework doesnot allow you to create multiple
assemblies of a single project, but we can achieve this target as mentioned here.
http://www.codeproject.com/aspnet/VSMaker.asp
but you see this is not the appropriate way, if one really wants to split the project then I would reccommend to create seprate class library for every module, instead of generating
a dll for every page as mention in the link given above.

Q19)What is GAC?

Ans) GLOBAL ASSEMBLE CACHE, It is a folder located in %system%\\assembly. It is a global
cache for assemblies. Any DLL located in this folder can have full access of using CLR.

Q20)What is machine.config?

Ans) This is configuration file located in c:\\Windows\\Microsoft.NET\\Framework\\{Version Number}\\CONFIG. It holds the information about the dlls, proxy setting and lot more stuff.

Q21)What different types of session state Management we have in asp.net?

Ans) There are following three ways of state managment.
A) Sessions
B) Query String
C) Cookie

Q22)What are cookies?

Ans) It is a small piece of information, residing on client side for the sesssion managment. since web is a connection less medium that is why we need a cookie to persist the connection information.

Q23)What is Cache?

Ans) well caching is a process of storing objects in memory for a specified time period. instead of getting connection to the database and get the new results caching store result in memory and use those results to display And after the time expire it gets the new result from the database and again store in the memory.
we can set cache of the page by writing following directive.
<%@OutputCache Duration="60" VaryByParam="none" %>

Q24)What is AJAX?

It is a programming technique which use to make web pages more responsive by exchanging small amount of information in the way that user dont get idea for it, and instead of page reload or refresh it gets the data from the server.typically it uses the following combination.
HTML / CSS, DOM (Client side scripting) and XMlHttpRequest object

Q25)Is AJAX a language?

Ans) No it is an efficient use of different languages, it is a technique.

Q26)What is the difference between syncronus and asyncronus?

Ans) well synchronus is a connection maintained medium, meaning that connection is maintained between until the work finish. Cell phone Call is a best example for that. I Make a call to my friend now I am connected to him, and the connection is remain established until I disconnect the line whereas asyncronus is a connectionless medium in which we we establish connection just to pass parameter, and then get disconnected. Think about SMS, I connnect to my firnd cell phone just for a second to leave a message, as soon as message sent connection will destroy.


Q27)What is an Assembly?

Ans) Assembly contain inermediate language code which can be execute by CLR, complilers of differnet .net languages such as VB.net , C# generate IL Code in assembly which then can use by CLR.
There are two types of assemblies, (EXE) and (DLL)

Q28)Can an assembly contains more then one classes?

Ans) Yes,

Q29)What is strong name?

Q30)What is the difference b/w client and server side?

Ans) Client is one who is requesting services where as service is providing services.

Q31)What we need for the deployment of a asp.net we application?

Ans) Any webserver that support .net framework. commonly, we use IIS to deploy asp.net application. We use aspnet_regiis (.net command prompt) to install .net framework on any IIS.

Q32)what is the purpose of IIS?

Ans) Internet Information Server, It is a web server that help us to run dynamic web sites.

Q33)Difference between http and https?

Ans) Http is a typical protocol used for data travelling over the web, It is not secure. where as Https is a secure

Q34)what is purpose of aspnet_wp.exe ?

Ans) This is a process used by IIS to execute asp.net application.

Q35)what is an ISAPI filter?

Ans) Internet server Application Programming Interface, It must be written is C++ and the compiled in DLL which then registered in IIS to run on the web server.

Q36)what do you mean by HTTP Handler?

Ans) It is a .net Componenet that implements System.Web.IHTTPHandler interface, any class that inherit this interface can be work as a target of HTTP Request, For HTTPHandler to work we need to define a following line in config file as well or if you ever open machine.config file you will get the following lines which are responsible for showing different file type.

. . . . . .
. . . . . .

Q37)What is the purpose of Global.asax?

Ans) It is an Asp.net Application file, it contains the code for responding to application level and session level events raised by asp.net application.

Q38)What is the significance of Application_Start/Session_Start/Application_Error?

Ans) Application_Start fires whenever the application start or you re-upload bin (dlls) where as session_start is specific for a user means if a new session create for a user this events fire. Application_Error is fire when any error occured.

Q39)What is the difference between the inline and code behind?

Ans) Inline code is written with HTML in <% %> where as code behind code is written in .aspx.vb file.


Q40)what is side by side execution?

Ans) We can run multiple version of .net framework on one system,for example currently I am running 3 versions of .net framework 1.0,1.1 and 2.0. this feature of microsoft known as side-by-side execution.

Q41)can we have two different versions of dot net frameworks running on the same machine?

Ans) That is what Side-by-Side executation is.

Q42)What is CLR? Difference b/w CLR and JVM?

Ans) Well, the basic difference between two is that CLR use intermediate language where as JVM use bytecode.

Q43)What is CLI?

Ans) It is the main component of .net framework, It provide Hight Level language Interoperablity means, Application written on C# can easily by integrated with vb.net. This Target is achieved with the help of CLI (Common Language Infrasructure). It also describe the following four aspects.
CTS (Commong Type System).
Meta Data
CLS (Common Language Specification).
Virtual Execution System (VES)

Q44)What is CTS?

Ans) It provide you with the base set of data type, A data type define by CTS can use in any of .net framework language. Furthermore, Every thing in CTS is an object, means every data type is derived from System.object.

Q45)Any idea of aspnet_regiis?

Ans) It is used to register asp.net in IIS, it can be access from .net Command Prompt or .net framework Directory.

Q46)Any idea of ASP NET State Service?

Ans) Well, Asp.net State service is off by default but In windows 2003 it is installed by default. It is used to manage session State on a computer.

Q47)What is the difference between stroed procedure and stored function in SQL?

Ans) There are following basic difference between them
Function can return a table variable where as sp cannot.
T-SQl ignore error in Sp and proceed to next line where as function stops.
You Can use sp in XML For Clause , but Function can't be used there


Q48)Can we have an updateable view in SQL?

Ans) no , they are read only.

Q49)What is connection pooling? how can we acheive that in asp.net?

Ans) Well, there is a pool for database connections, the moment when we request for database connection ADO.net check if there is a recent connection in the pool with the same connectionString, If it find, it used that otherwise create a new connection.We can use connection Pooling in asp.net by System.Data.SqlClient.SqlConnectionPoolManager furthermore, We can define pooling attribute in connection string
pooling=false|True
Min Pool Size=50
Max Pool Size=600

Q50)What is DataSet?

Ans)Dataset is like a recordset, when we get any result from datasource, dataset fill it self with the result and destroy the connection from datasource. It is also called disconnected datasource. It remove the over head of maintaining connection with the database, but can make application slow where there is large sum of results.

Q51)What is the difference between typed and untyped dataset?

Ans) As the name mention, untyped dataset are not structured where as typed dataset are keenly structure.
We need to do some extra coding but by that we can make our code look pretty and understandable.

Q52)What is the difference bewteen accessing the data throgh the dataset and datareader?

Ans)Dataset doesnot maintain connection with the datasource where as in data reader we explisitly need to close the connection. where as datareader is forward only and we have not such restriction in dataset.

Interview Questions Series 1

Q1) Describe the difference between a Thread and a Process?Ans) Process is a collection of multiple threads ans is a unit of allocation. whereas thread is a unit of execution which allow an application to run multiple task, multiple threads in a process share the same virtual memory.Q2)What is a Windows Service and how does its lifecycle differ from a “standard” EXE?Ans) Windows services are the long running Process and have no user interface and control by Service Control Manager. Windows Services can start when the os starts and all the logs of windows service maintain in Widnows Event Log. Q3)What is the difference between an EXE and a DLL?Ans) An Exe can run independently where as DLL need an executeable file(EXE) to perform any function. DLL is in Process file where as EXE is out Process file. Q4)What is strong-typing versus weak-typing? Which is preferred? Why?Ans) Strong type check the variable and data type as soon as possible usually at compile time where as Weak type reverse the situation means as late as possible at runtime. furthermore,the preference is depends upon what are you up to. If you are writing script then use weak typing and if you are writing application in which speed is really matters then I sugges you should do strong type.Q5)What are PDBs? Where must they be located for debugging to work?Ans)PDB is Program database file which contain the state information.It contains the debug information of assembly.Q6)What is FullTrust? Do GAC’ed assemblies have FullTrust?Ans) Fulltrust assemblies means your code is allowed to do any thing, All .net Permission granted. Yes GAC Have full trust permission because it reside on local hd but we can change that using CASPOL.Q7)Why is catch(Exception) almost always a bad idea?Ans) Well , being a programmer if a LOC expected to throw error then why dont we catch directly that specific exception for example instead of catch(Exception ex){it catches all the exception and perform accrodingly} we can catch(NullException ex) {It catches only NullException type} Good Idea.Q8) What is the difference between Debug.Write and Trace.Write? When should each be used?Ans) Debug.write only works in Debug mode whereas Trace.write works in both Debug and release mode.Q9) What is Reference Type and value Type?Ans) String is Reference Type.Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short,strut, uint, ulong, ushortValue types are stored in the StackReference type - class, delegate, interface, object, stringReference types are stored in the Heap

Exception handling in asp.net

Exception handling in asp.netFrankly speaking, handling exceptions is a real art, and especially when you break your application in different chunks of classes and forms. Some time it becomes unimaginably difficult to catch a simple error at runtime without managing exception block. When it comes to extendibility of the application unexpected errors become a night mare for programmers.After the request of many friends who are the regular reader of this blog , I have decided to share my approach to handle exception.Have look at the following piece of code.
Namespace CustomExceptionsPublic Class Exception_SqlInjectionInherits ExceptionPublic Sub New()MyBase.New(ConfigurationSettings.AppSettings("Exception_SqlInjection"))MyBase.Source = "SqlInjection"End SubEnd ClassEnd Namespace
In the above code I am doing a real simple thing. Let me just give you a quick Idea
Namespace CustomExceptionsPublic Class Exception_SqlInjectionInherits Exception
Creating a namespace called “CustomExceptions” and a class under that namespace which is called “Exception_SqlInjection”, Notice that this class is inheriting “Exception” class. It means that “Exception_SqlInjection” is now become an exception I can call it anywhere.
Public Sub New()MyBase.New(ConfigurationSettings.AppSettings("Exception_SqlInjection"))MyBase.Source = "SqlInjection"End SubEnd ClassEnd Namespace
Constructor of “Exception_SqlInjection” in which we are calling the base class and providing the error message. Notice that we are reading error messages from web.config file (App settings). And in the 3rd line we are simply giving the source to the base class which is a simple text “SqlInjection”The web.config for the code above will look like this.
 <configuration>  <appSettings>      <add key="Exception_SqlInjection" value="Sorry Kid !!! but you cannot apply sql injection here try some where else ...... and by the way better luck next time :)"/>       </appSettings></configuration>
   The moment when we call the above created exception the value of the key "Exception_SqlInjection" will be returned by exception as message.Now lets get down to the implementation of the above exception in a real life case. The scenario is I want to check the input of the user On Click event of Command Button.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickIf TextBox1.Text.IndexOf("'") <> -1 ThenThrow New CustomExceptions.Exception_SqlInjectionEnd IfEnd Sub
The above code is simply check the Textbox for the character “ ‘ “ and if it found any it will just throw a yellow page to browser.BINGOOOOOOO !!!!!The purpose of using exception is not to see the yellow screen every time, don’t be upset the next chunk of code will catch this exception and take the appropriate action. Here you might be thinking that why there is need to throw our own exception. So the answer is some time application may need to behave different on different occasions. That is why we use exceptions to throw our own error in a proper way.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickTryIf TextBox1.Text.IndexOf("'") <> -1 ThenThrow New CustomExceptions.Exception_SqlInjectionEnd IfCatch ex As CustomExceptions.Exception_SqlInjection'might you want the system to block this IP, or trace the IP or to email yourself about this attack.Response.Write("custom Exception :" & ex.Message)Catch ex As ExceptionResponse.Write("default Exception :" & ex.Message)End TryEnd Sub
Now you have created your own exception and catching it at the front end. Furthermore, if you like to create more exceptions just create another class with the namespace “CustomExceptions”.Example :
Namespace CustomExceptionsPublic Class Exception_SqlInjectionInherits ExceptionPublic Sub New()MyBase.New(ConfigurationSettings.AppSettings("Exception_SqlInjection"))MyBase.Source = "SqlInjection"End SubEnd ClassPublic Class Exception_WebConfigInherits ExceptionPublic Sub New()MyBase.New("The key value you are looking for is not available in the web.config this is the crucial problem please contact to administrator")End SubEnd ClassEnd Namespace
In the newly created class I pass a simple text instead to the base class instead of calling Web.Config file for error message.Cheers.

Writing XML File Dynamically

Hey Geeks,Writing xml file in .net application is quit general but I have noticed most of the people do this work in a loong and wrong (in my opinion) way. They write the xml file with the help of dataset which is more like a database...... Yes offcourse resource heavy. So let us make this operation quit simple and easy. consider the following XML Schema. We will write the same schema from our code to a local file.
XML Schema :
<?xml version=“1.0“ encoding=“utf-8“?><Items><Item><ItemId>3</ItemId><ProductName>Pine Apple</ProductName><Price>30 $</Price><Item><Items>
VB.net Code :
Dim XMLDoc As New XmlDocumentXMLDoc.Load(Server.MapPath("MyData.xml"))Dim XEle As XmlElement = XMLDoc.CreateElement("Item")Dim XTxt As XmlText'XMLDoc.DocumentElement.AppendChild(XEle)XEle = XMLDoc.CreateElement("ItemID")XTxt = XMLDoc.CreateTextNode("3")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XEle = XMLDoc.CreateElement("ProductName")XTxt = XMLDoc.CreateTextNode("Meera")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XEle = XMLDoc.CreateElement("Price")XTxt = XMLDoc.CreateTextNode("50 $")XMLDoc.DocumentElement.AppendChild(XEle)XMLDoc.DocumentElement.LastChild.AppendChild(XTxt)XMLDoc.Save(Server.MapPath("MyData.xml"))