c#

How to use XMLTextWriter to create an XML document in C#

You can create a XML document, by using the basic XmlTextWriter class. This class works like StreamWriter relative, except that it writes XML document instead of ordinary text file. You can follow the next process:

1. Create or open the file

2. Write to file, moving …

Learn more

How to upload files to the Web server with FileUpload control in C#

ASP.NET includes a control named FileUpload that allows website users to upload files to the web server. The FileUpload control manages the posted file data, by examining it, disregarding it, or saving it to a back-end database or a file on the web server.   The FileUpload control represents the <input  type = “file”> HTML tag and …

Learn more

How to download a file from the Web server in ASP.NET in C#

You should use the Directory FileInfo classes to collect and present the names of the files you want to make available for download to the end user.  You can display their names in a ListBox with a button to initiate the download. When the user clicks the button, stream the selected file to the browser.  The next picture …

Learn more

How to use LINQ group clause to group results in C#

Web developers can use LINQ group clause to group their results based on a key that they specify. For example Web developers could specify that the results should be grouped by the City so that all clients from New York or San Francisco are in individual groups. In this case client.City is the key.

 

var qryClientsByCity =

from …

Learn more

How to use LINQ expression inline in C#

Web developers can create and call a method inline based on LINQ expression. For example they can create a function named TestClient() that examines a client an return true or false based on whether they want to include it in the results:

 

private bool TestClient(Client client)

{

return client.LastName.StartsWith(“T”);

}

 

Web developers could use the TestClient method like this:

 

var matches = …

Learn more

How to use LINQ where clause to filter results in C#

Web developer can modify the where clause in LINQ statement to filter the results and to include only those that match a specific condition. The next code shows how to find clients who have a last name that starts with a specific letter:

 

var matches = from client in clients

where client.LastName.StartsWith(“P“)

select client;

 

Web developer can combine …

Learn more

How to use LINQ expression to do projection in C#

Web developer can use approach described in the article How to use LINQ expression to get a subset of data in C# to define a new class that wraps just the information he/she wants to return. For example, if he/she wants to get both the first and last names but he/she wants to store them in separate strings, …

Learn more

How to use LINQ expression to get a subset of data in C#

In the article How LINQ expression is composed LINQ select clause was described. Web developer can change it to get a subset of data. For example, he/she could pull out a list of first name strings like this:

var matches = from client in clients

select client.FirstName;

 

or a list of strings with both first, middle and last …

Learn more

How LINQ expression is composed in C#

LINQ expressions have a superficial similarity to SQL queries, but the order of the clauses is rearranged.

All LINQ expressions must have a from clause that indicates the data source and a select clause that

indicates the data Web developer wants to retrieve (or a group clause that defines a series of groups into which the data should be placed). …

Learn more

How LINQ works with in memory collections in C#

Web developer uses in this case the simplest form of LINQ – LINQ to Objects.  Let for example Web developer has some sort of data class, like the Clients class shown next:

 

public class Client

{

public int ClientID { get; set; }

public string FirstName { get; set; }

public string LastName { get; set; }

Learn more