Monday, November 10, 2008

Create and Delete Virtual Directory Programmatically

create a function to create a new virtual directory and set some properties of the new virtual directory.

public void CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
DirectoryEntry NewVirtualDir;
NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
NewVirtualDir.Properties["Path"][0] = Path;
NewVirtualDir.Properties["AccessScript"][0] = AccessScript;NewVirtualDir.CommitChanges();
}
You can call this function like
CreateNewVirtualDirectory(1, "MyNewVirtualDirectory", @"C:\Inetpub\wwwroot\MyDir", true)


create a function to Delete virtual directory .

public void DeleteVirtualDirectory(int ServerId, string VirtualDirName)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
Object[] Parameters = {"IIsWebVirtualDir",VirtualDirName};
Parent.Invoke("Delete",Parameters );
}

Thursday, October 9, 2008

ASP.NET Tab in IIS is Missing

Here are the steps to fix the issue:

1) Stop the IIS Admin service (and any services that depend on it)

2) Open C:\WINDOWS\system32\inetsrv\MetaBase.xml in notepad or your favorite XML

Editor. _DELETE_ the line that reads ‘Enable32BitAppOnWin64=”TRUE”’

3) Start -> Run -> iisreset

Error while trying to run project: Unable to start debugging on the web server

Error while trying to run project: Unable to start debugging on the web server
About the “Error while trying to run project: Unable to start debugging on the web server.” Error.

Open your Internet Information Services manager and from the [your machine]/Web Sites/ Default Web Site node select the virtual folder which stores your project. Right Click and select Properties to select the ASP.NET tab page. Make sure the correct version ASP.NET Version is selected.

Thursday, August 28, 2008

Build Error (ALINK: error ):Satellite build for culture ' xx' failed.

When you build a project in Microsoft Visual Studio .NET 2003 that includes many forms and controls that you can localize, the build process may not succeed and you may receive an error message that is similar to the following in the output window:

Building satellite assemblies... Satellite build for culture 'fr' failed. Please see the output window for more detailed error information. ALINK: error AL1022: Error reading embedded resource 'C:\Visual Studio Projects\WindowsApplication1\obj\Debug\For' -- The system cannot find the file specified.


Solution

Confirm that the machine has Microsoft Visual studio .net 2003 Service pack 1 is installed. If not installed then install it. This will solve the above issue.

Saturday, June 14, 2008

LINQ Query Expression Steps

LINQ Actions
LINQ query operation consists of the following actions,









Our query expression syntax looks like this,



First Query
Let us get started with our first utility function which is to display all names in our names array



Here from array names, take each array element into a variable called name and select them all.

Sunday, May 25, 2008

Visual Studio 2008 - LINQ Ordering Operators Sample

OrderBy - Simple
This sample prints an alphabetically sorted version of an input string array. The sample uses orderby to perform the sort.
publicvoid Linqsample()
{
string[] colors = { "Blue", "red", "green" };
var sortedcolorss = from c in colors
orderby c
select c;
Console.WriteLine("The sorted list of colors:");
foreach (var c in sortedcolors)
{
Console.WriteLine(c);
}
}
Result
The sorted list of words:
Blue
green
red

Saturday, May 24, 2008

Visual Studio 2008 - LINQ Projection Operators Sample

Select - Simple
This sample prints a integers Hundred greater than those in an input array. The sample uses the expression in the select clause to add hundred to each element in the new sequence.

public void Linqsample()

{

int[] numbers = { 500, 400, 100, 300, 900, 800, 600, 700, 200, 000 };

var numsPlusOne = from n in numbers

select n + 100;

Console.WriteLine("Numbers + 100:");

foreach (var i in numsPlusHundred)

{ Console.WriteLine(i); }

}
Result
Numbers + 1:

600

500

200

400

1000

900

700

800

300

100

Visual Studio 2008 - LINQ Restriction Operators Sample

Where - Simple 1
This sample prints each element of an input integer array whose value is less than 500. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value.


public void LinqSample()
{
int[] arr= { 500, 400, 100, 300, 900, 800, 600, 700, 200, 000 };
var lowNums = from result in arr
where result < 500
select result ;
Console.WriteLine("arr < 500:");
foreach (var n in lowNums)
{
Console.WriteLine(n);
}
}
Result:
arr < 500:
400
100
300
200
000

Visual Studio 2008 - LINQ Partitioning Operators Sample

Partitioning Operators

Take - Simple

This sample uses Take to generate a sequence of the first three elements of an integer array. It then iterates through the sequence to print the results.
public void LinqSample()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var first3Numbers = numbers.Take(3);
Console.WriteLine("First 3 numbers:");
foreach (var n in first3Numbers)
{
Console.WriteLine(n);
}
}
ResultFirst 3 numbers:
5
4
1

LINQ in Visual Studio 2008

LINQ stand for Language-Integrated Query is now available as an integral part of Visual Studio 2008. Visual Studio gives a native syntax to developers in the form LINQ to C# and VB.Net for accessing data from any repository. The repository could be in memory object, database (still MS SQL Server only) and XML files.

what LINQ is doing ?
Basically LINQ address the current database development model in the context of Object Oriented Programming Model. If some one wants to develop database application on .Net platform the very simple approach he uses ADO.Net. ADO.Net is serving as middle ware in application and provides complete object oriented wrapper around the database SQL.

LINQ has a great power of querying on any source of data, data source could be the collections of objects, database or XML files. We can easily retrieve data from any object that implements the IEnumerable interface. Microsoft basically divides LINQ into three areas and that are give below.
o LINQ to Object {Queries performed against the in-memory data}
o LINQ to ADO.Net
o LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}
o LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}
o LINQ to Entities {Microsoft ORM solution}
o LINQ to XML (formerly XLinq) { Queries performed against the XML source}

1. Code 1
int[] numbers = new int[] {100,101,102};
var result = from output in numbers where output <>

select output;
foreach(int count in result)
Console.WriteLine(count);
Output:
100
101
102
All type of SQL Operates are available in LINQ to Object. like Sum Operator in the following code.
2. Code 2
int[]numbers = new int[] {2,4,6,2};
int result = nums.Sum();
Console.WriteLine(result);

LINQ to object provided main types of Operator Type that are give below

Operator Types Operator Name
Aggregation • Aggregate • Average • Count • LongCount, • Max, • Min, • Sum

Conversion • Cast, • OfType, • ToArray, • ToDictionary, • ToList,
•ToLookup, ToSequence
Element • DefaultIfEmpty, • ElementAt, • ElementAtOrDefault, • First,
• FirstOrDefault, • Last, • LastOrDefault, • Single, • SingleOrDefault
Equality • EqualAll
Generation • Empty, • Range, • Repeat
Grouping • GroupBy
Joining • GroupJoin, • Join
Ordering • OrderBy, • ThenBy, • OrderByDescending,
• ThenByDescending, • Reverse
Partitioning • Skip, • SkipWhile, • Take, • TakeWhile
Quantifiers • All, • Any, • Contains
Restriction • Where
Selection • Select, • SelectMany
Set • Concat, • Distinct, • Except, • Intersect, • Union