asp.net Archives - Page 2 of 2 - Coding Sharp

Tag: asp.net

Writing XML with the XmlWriter class

Writing XML with the XmlWriter class

Asp.Net, C#.Net
In previous article we have see about writing and reading text document, but now it's time to start dealing with XML file. Anyhow XML is just a plain text, we can simply start writing an XML tags to the file and save it with .xml file extension. But for .net framework it is very easy and safe to handle. For writing an XML file .net framework provides two different options. XMLWriter and XmlDocument, we will see XMLDocument in the next article. In this article we will focus on XMLWriter approach Let's see the basic different between XmlWriter and XmlDocument. XMLWriter uses less memory compare to XmlDocument, that is the only 1 issue if we are writing a vey big file. Another difference is if we are modofing an xml file using XmlDocument, we can read an exisitng file, change it as req...
StreamReader

StreamReader

Asp.Net, C#.Net
StreamReader class In my previous article we have have seen how to read from text file using File class and how to write into text file using StreamWriter class. In this article we will see how to read from text file using StreamReader  class. Using Statements: It is recommended to use using statements while we are using StreamReader class, which ensures that is is removed from the memory once it is no longer needed. The syntax is very easy to use. StreamReader class reads text file, it is available in System.IO namespace. It provides very good performance. Using StreamReader we can read a file synchronously and asynchronously, we need to provide a relative or absolute path to the file. Lets check with the example that how to synchronously read a line from text file using StreamR...
Understanding StreamWriter class

Understanding StreamWriter class

Asp.Net, C#.Net
We have seen how to write in text file using File class in our previous article. Today we will see how to use StreamWriter class to write in a text file. This class is very helpful to write text data into files. This class contains method to write to a file synchronously like Write and WriteLine or asynchronously WriteAsync and WriteLineAsync. Using Statements. It is recommended to use using statements while we are using Stream Writer class, which ensures that is is removed from the memory once it is no longer needed. The syntax is very easy to use. Lets check with the example that how to synchronously write to a text file using Stream Writer class. First we need to declare and initialize an instance of the class with using statement. It is available is available in System.IO namespace...
How to Read from a Text File using C#

How to Read from a Text File using C#

Asp.Net, C#.Net
In previous article we have see "How to write to a Text File using C#", Now in this article we are going to learn how can we read text file using C#. In most of the application either we are writing something to text file or reading from text file. Reading from and writing to text file is essential for major application. So lets see the code for reading text file using C#. The main important class is File for Read from text file which exists in System.IO namespace. So first we need to import System.IO namespace to our project. Now lets see example for ReadAllText method ReadAllText ReadAllText method will read all the content of a given file. It will take 1 parameter as a full file path. Example #1 ReadAllLines ReadAllLines method will read all the lines of a give...
How to write to a Text File using C#

How to write to a Text File using C#

Asp.Net, C#.Net
In this article we will see how to write text in txt file using C#. In our dot-net application frequently we required to either read from text file or write to text file. We will see how to read from txt file later. Here we will focus on writing into text file. The main class file we are going to user for either reading or writing is "System.IO.File" class. File class contains a various methods to write in a txt file. To write all the text in a file see the below example Example For WriteAllText Now you can also write the list of lines into a text file. See below example for more detail and syntax. Example For WriteAllLines Above both example code are creating a new file or over right an existing file. Now lets see how to append some text to an existing fi...
Understand the value type and reference type

Understand the value type and reference type

Asp.Net, C#.Net, Difference, OOPS
In previous article we have seen difference between primary key and unique key. Today we will see the difference between value type and reference type. Let first see what are the value types and what are the reference types. What are Value Types? Variables which stores direct data are called value types they are stored on a stack. They contains the actual value rather then reference. For an example enum, structure int are value types. What are Reference Types? Variables which stores reference of actual data are called Reference types. They are stored on heap but contain the address on heap. For an example Array, class, object, string, delegate, interface are reference type. Now lets see the difference between both of them. Before that let me show you the difference betwe...
Difference between WebForm and MVC in Asp.Net

Difference between WebForm and MVC in Asp.Net

Asp.Net, C#.Net, Difference
Asp.net framework is a small part of .Net framework for building and running web applications. We can design and develop a web application or website using either Asp.Net MVC for Web Forms. In this article we will see some important difference between Asp.Net Web Forms and Asp.Net MVC. Difference between WebForm and MVC in Asp.Net Asp.Net Web Form Asp.Net Web MVC Asp.Net Web Form is not an Open Source. Asp.Net Web MVC is an Open Source. In Asp.Net you will have a server controls like TextBox, Buttons etc. In Asp.Net MVC you will have html helpers. For client side state management Asp.Net Web Forms supports view state In Asp.Net MVC view state is not supported. Asp.Net Web Form follows Web Forms Syntax Asp.Net MVC follow customizable syntax (by default it'...