Asp.Net Archives - Page 2 of 2 - Coding Sharp

Asp.Net

Bind DropDownList in Asp.MVC using Range/Fixed value

Bind DropDownList in Asp.MVC using Range/Fixed value

Asp.Net, Asp.Net MVC, C#.Net
In most of the application we are using dropdown to select some value from predefined list of value. Some of them are getting bind from the database table, some of are getting bind using Enum value while some of them are getting bind using some fix value like 1 to 10, or month drop-down 1 to 12. In this article post we will see how to bind drop-down using range value in MVC. Below if the sample code which will bind 2000 to 2014 in year drop-down. above code will produce output as below image. In the above code we have just write a code in view only, there is no server side code. Now in some cases we need to bind some data which are not in particular range like "2000, 2002, 2004, 2006, 2008" or some string type fixed data then we can not use "Enumerable.Range", so how can w...
How to integrate SagePay payment form using Asp.Net MVC

How to integrate SagePay payment form using Asp.Net MVC

Asp.Net, C#.Net, SagePay, Special Posts
Introduction In Europe Sage Pay is independent payment service provider. It is one of the most trusted payment brands in Europe. Sage Pay makes payments safe and secure. Payment security and fraud prevention are two of their top priorities. Sagepay provides various integration option for your e-commerce website. Like 1. Form Integration 2. Server Integration 3. Server Iframe integration 4. Direct Integration In Direct integration, only your server will be save card data and host checkout page, while in all other 3 integration it will be save card data to the SagePay server and checkout pages will be there only. You do not need to create checkout page for that. Today we are going to understand how Form Integration will work. Setting in Web.Config Let's first list ...
XmlDocument class

XmlDocument class

Asp.Net, C#.Net
In the previous article we have seen how to write an XML file using XmlWriter class, in this article we will see how to write an XML file using XmlDocument class. Both are writing the XML file only, however when we want to update an existing XML file then XmlDocument class will be easy to use. Because XmlWriter class will use higher memory consumption. Now look at the below sample code Above code will produce below output As we can see, first we have created an object of XmlDocument class. It will be used to create new element and new attribute both using the CreateElement() and CreateAttribute() methods. Each time we will do the same process, what I mean here is if we want to create 3 nodes in the root element developers then we will do use document object 3 times to cre...
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'...