C#: Method wich sets attributes to normal for each file and directory recursively, and then deletes them

http://stackoverflow.com/questions/611921/how-do-i-delete-a-directory-with-read-only-files-in-c

method wich sets attributes to normal for each file and directory recursively, and then deletes them:

private static void DeleteFileSystemInfo(FileSystemInfo fsi)

{

fsi.Attributes = FileAttributes.Normal;

var di = fsi as DirectoryInfo;

if (di != null)

{

foreach (var dirInfo in di.GetFileSystemInfos())

DeleteFileSystemInfo(dirInfo);

}

fsi.Delete();

}

C#: Set default version of Visual Studio

http://social.msdn.microsoft.com/Forums/en/vssetup/thread/568e32af-d724-4ac6-8e8f-72181c4320b3

Set default version of Visual Studio

Problem:

I have both VS 2005 & VS 2008 installed. I need VS 2008 to be the default version. What registry changes must I make to get this to happen?

Soln:

· I had the same issue long ago and dug out the answer, it was much more difficult to find than it should be. I believe the setting we’re all looking for is in the registry at:

HKLM\Software\Microsft\Windows\CurrentVersion\App Paths\devenv.exe

I set this default string to the filespec of the devenv.exe I want to use when I double-click on a *.sln file

C#: Overview of C# 3.0 Anonymous Types

http://www.ezzylearning.com/tutorial.aspx?tid=7413831&q=overview-of-csharp-3-0-anonymous-types

Overview of C# 3.0 Anonymous Types

Author: Waqas Anwar – Posted Date: 10-July-2009 – Category:Visual C#
Share |

Download Source Code
Microsoft introduced some great new features in C# 3.0 to make developers more productive. Most of those features are introduced to support Language Integrated Query (LINQ) but they can also be used in many other scenarios. One such feature is Anonymous Types that allows you to define a class with some simple encapsulated fields without any associated methods, events or functionality. In this tutorial I will give you overview of C# 3.0 Anonymous Types.
What is Anonymous Type?

There are times in programming when you would like to define a class that holds data temporarily and which is not required to be reused anywhere else in the application. This is where anonymous type helps which provides you massive shortcut for creating types on the fly by using extended syntax of the new operator. When you define anonymous type you also use object initialization syntax along with the new var keyword.

For the purpose of this tutorial, I have created a simple C# Console Application in Visual Studio 2008. Inside the main Program I am creating the following anonymous type to illustrate its syntax.
var studentInfo = new { ID = 1, Name = "Waqas", Fee = 3000.00 };
Or
var studentInfo = new {
ID = 1,
Name = "Waqas",
Fee = 3000.00
};
The above anonymous type is representing a Student object that has few properties such as ID, Name and Fee. The first thing you should note that anonymous types are types with no name and as a programmer you don’t have any control on the name of anonymous type. That’s why you need to implicitly typed it by using var keyword. At compile time, the C# compiler will generate a uniquely named class automatically and because you don’t have information about the name of the type so the use of var keyword is mandatory.

The second thing to notice in the above syntax is the use of new keyword without the type name and the use of object initializer syntax to define and set the type properties and their values. When you create anonymous type the compiler automatically build a type inherited from System.Object and then called its default constructor behind the scene. Once you have defined the properties of your anonymous type you can access them by using normal C# syntax as shown below:

Console.WriteLine("Student ID: " + studentInfo.ID);
Console.WriteLine("Student Name: " + studentInfo.Name);
Console.WriteLine("Student Fee: " + studentInfo.Fee);

Keep in mind here is that all the properties you define inside your Anonymous Type are read only so following line will never compiler.
studentInfo.ID = 4;

As I mentioned that all Anonymous Types inherit from System.Object by default so they have access to the methods such as ToString(), GetType() etc. In the case of anonymous type the ToString() method returns a string that has all the properties and their values inside. For example if you will call the ToString() method of our studentInfo object you will get the output shown below. Notice how curly braces are attached automatically with name/value pairs.

{ ID = 1, Name = Waqas, Fee = 3000 }

It is also possible to compose one anonymous type inside another anonymous type. Check the following example:

var emp = new {
ID = 1,
Name = "Ali",
Address = new {
Street = "Baker Street",
City = "London",
Country = "UK"
}

};

In the example above I have created an anonymous type holding employee ID and Name and another anonymous type to store the employee Address information. You can access both anonymous types as you access normal classes and their composed objects.

Console.WriteLine(emp.ID);
Console.WriteLine(emp.Name);

Console.WriteLine(emp.Address.Street);
Console.WriteLine(emp.Address.City);
Console.WriteLine(emp.Address.Country);

Although anonymous types provides you very quick and short syntax to create types in your applications but you would never stop defining strongly typed classes because of the following limitations.

  1. You don’t have control on the name of the anonymous type
  2. Anonymous Type always inherit from System.Object
  3. The properties of an anonymous type are read only
  4. You cannot create events, operators or methods inside anonymous type
  5. You cannot override any method of System.Object in anonymous type
  6. Anonymous types are sealed types so you cannot inherit from anonymous type
  7. Anonymous types are always created using default constructor.

With all the above limitations in mind, you may be thinking why you would ever need to use anonymous types. The answer is that you need to use them when you will start using LINQ queries because you will find the anonymous type syntax very quick and useful in many cases.

Download Source Code

SQL: WITH common_table_expression for finding direct/indirect subordinate of manager

http://msdn.microsoft.com/en-us/library/ms175972.aspx

WITH common_table_expression

Example: 1 : WITH common_table_expression for finding direct/indirect subordinate of manager

USE AdventureWorks2008R2;

GO

WITH DirectReports(ManagerID, EmployeeID, Title, EmployeeLevel) AS

(

SELECT ManagerID, EmployeeID, Title, 0 AS EmployeeLevel

FROM dbo.MyEmployees

WHERE ManagerID IS NULL

UNION ALL

SELECT e.ManagerID, e.EmployeeID, e.Title, EmployeeLevel + 1

FROM dbo.MyEmployees AS e

INNER JOIN DirectReports AS d

ON e.ManagerID = d.EmployeeID

)

SELECT ManagerID, EmployeeID, Title, EmployeeLevel

FROM DirectReports

ORDER BY ManagerID;

GO

SQL Error: Cannot create indexed view because it contains one or more UNION, INTERSECT, or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION, INTERSECT, or EXCEPT operators of the original view.

Cannot create indexed view because it contains one or more UNION, INTERSECT, or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION, INTERSECT, or EXCEPT operators of the original view.

This error occurs when you try to create an index on a view that contains a UNION, INTERSECT, or EXCEPT operator. For example: the following statement will raise the above error.

http://stackoverflow.com/questions/751838/create-an-index-on-sql-view-with-union-operators-will-it-really-improve-performa

You cannot create an index on a view that makes use of a union operator. Really no way around that, sorry!

I would imagine you’ve seen this, but check out this MSDN page. It gives the requirements for indexed views and explains what they are and how they work.

As to whether or not you’d see a performance benefit if you COULD index the view, that would depend entirely on the size of your tables. I would not expect any impact on creating separate indexed views, as I would assume that your tables are already indexed and you aren’t doing any joining or logic in the view.

Creating Indexed Views

http://msdn.microsoft.com/en-us/library/ms191432.aspx

understanding of Windows Security Identifiers (SIDs)

http://servermigrator.blogspot.com/2006/02/why-understanding-sids-is-important.html

Why Understanding SIDs is Important

An understanding of Windows Security Identifiers (SIDs) is important to successful server, server data and domain migrations.

The SID is a unique name (alphanumeric character string) that is used to identify an object, such as a user or a group of users in a network of NT/2000/XP/2003 systems.

Windows grants or denies access and privileges to resources based on ACLs, which use SIDs to uniquely identify users and their group memberships. When a user requests access to a resource, the user’s SID is checked by the ACL to determine if that user is allowed to perform that action or if that user is part of a group that is allowed to perform that action.

SIDs are NOT Portable

This information is useful for troubleshooting issues involving security reporting, server migrations and domain migrations.

All SIDs are unique within a given system and are issued by what is known as an "Authority" such as a domain or local server. While Windows 2000/2003 is most comfortable using SIDs in the form of a simple binary data structure, we humans like to see things in a simple string format so that we can more easily recognize them.

As a result, you and I never see SIDs in their native format but instead see things like S-1-5-12-7723811915-3361004348-033306820-1006.

The format of this SID breaks down as follows:

S – The string is a SID.
1 – The revision level.
5 – The identifier authority value.
12–7723811915-3361004348-033306820 Domain or local computer identifier
1006 – The RID (Generated for each object from 1000 and up)

Any group or user that is not created by default will have a RID of 1000 or greater. A RID is a Registered ID. This is the last portion of the SID. Once a RID has been issued it will never be used again even if the user and user account are deleted.
However there are always exceptions in Microsoft Windows. Certain RIDs (below 1000) are predefined:

500 – Administrator S-1-5-21—-500
501 – Guest S-1-5-21—-501
502 – KRBTGT S-1-5-21—-502

512 – Domain Admins S-1-5-21—-512
513 – Domain Users S-1-5-21—-513
514 – Domain Guest S-1-5-21—-514
515 – Domain Computers S-1-5-21—-515
516 – Domain Controllers S-1-5-21—-516
517 – Cert Publishers S-1-5-21—-517
518 – Schema Admins S-1-5-21—-518
519 – Enterprise Admins S-1-5-21—-519
520 – Group Policy Creator Owners S-1-5-21—-520
533 – RAS and IAS Servers S-1-5-21—-533

During a server or domain migration new accounts and groups are created on the target. Therefore; even if the account names are the same, new SIDs are created and any rights that the original account has or had, the new account does not.

There are two methods of dealing with SID disassociation:

SidHistory – Append the old SID to the new account (Windows 2000 and up). This method is available in domain migration only. There are known issues using this method.

ReACL Process – by creating a mapping between old and new SIDs, The new SIDs are appended or replaced for each ACL for files, folders, shares, local groups membership, printers, mapped drives, profiles and rights.

SIDs That Are Portable – Well Known SIDs

Well-known SIDs are a group of SIDs that identify generic users or generic groups. Their values remain constant across all operating systems and for this reason are termed well-known SIDs

You can find the well-known SIDs in Active Directory in a container called WellKnown Security Principals. To see this container, launch Adsiedit.msc or Ldp from the Windows Server 2003 Support Tools and use it to view the top-level containers inside the Configuration naming context.

A universal well-known SID is a SID that is common to all machines. That is, the value SID is the same on my machine as it is on yours.

These SIDs include BuiltIn accounts and groups (BuiltIn\Administrators) as well as label accounts such as the Everone group

Well Known SIDs

• SID: S-1-0
Name: Null Authority
Description: An identifier authority.

• SID: S-1-0-0
Name: Nobody
Description: No security principal.

• SID: S-1-1
Name: World Authority
Description: An identifier authority.

• SID: S-1-1-0
Name: Everyone
Description: A group that includes all users, even anonymous users and guests. Membership is controlled by the operating system. Note By default, the Everyone group no longer includes anonymous users on a computer that is running Windows XP Service Pack 2 (SP2).

• SID: S-1-2
Name: Local Authority
Description: An identifier authority.

• SID: S-1-3
Name: Creator Authority
Description: An identifier authority.

• SID: S-1-3-0
Name: Creator Owner
Description: A placeholder in an inheritable access control entry (ACE). When the ACE is inherited, the system replaces this SID with the SID for the object’s creator.

• SID: S-1-3-1
Name: Creator Group
Description: A placeholder in an inheritable ACE. When the ACE is inherited, the system replaces this SID with the SID for the primary group of the object’s creator. The primary group is used only by the POSIX subsystem.

• SID: S-1-3-2
Name: Creator Owner Server
Description: This SID is not used in Windows 2000.

• SID: S-1-3-3
Name: Creator Group Server
Description: This SID is not used in Windows 2000.

• SID: S-1-4
Name: Non-unique Authority
Description: An identifier authority.

• SID: S-1-5
Name: NT Authority
Description: An identifier authority.

• SID: S-1-5-1
Name: Dialup
Description: A group that includes all users who have logged on through a dial-up connection. Membership is controlled by the operating system.

• SID: S-1-5-2
Name: Network
Description: A group that includes all users that have logged on through a network connection. Membership is controlled by the operating system.

• SID: S-1-5-3
Name: Batch
Description: A group that includes all users that have logged on through a batch queue facility. Membership is controlled by the operating system.

• SID: S-1-5-4
Name: Interactive
Description: A group that includes all users that have logged on interactively. Membership is controlled by the operating system.

• SID: S-1-5-5-X-Y
Name: Logon Session
Description: A logon session. The X and Y values for these SIDs are different for each session.

• SID: S-1-5-6
Name: Service
Description: A group that includes all security principals that have logged on as a service. Membership is controlled by the operating system.

• SID: S-1-5-7
Name: Anonymous
Description: A group that includes all users that have logged on anonymously. Membership is controlled by the operating system.

• SID: S-1-5-8
Name: Proxy
Description: This SID is not used in Windows 2000.

• SID: S-1-5-9
Name: Enterprise Domain Controllers
Description: A group that includes all domain controllers in a forest that uses an Active Directory directory service. Membership is controlled by the operating system.

• SID: S-1-5-10
Name: Principal Self
Description: A placeholder in an inheritable ACE on an account object or group object in Active Directory. When the ACE is inherited, the system replaces this SID with the SID for the security principal who holds the account.

• SID: S-1-5-11
Name: Authenticated Users
Description: A group that includes all users whose identities were authenticated when they logged on. Membership is controlled by the operating system.

• SID: S-1-5-12
Name: Restricted Code
Description: This SID is reserved for future use.

• SID: S-1-5-13
Name: Terminal Server Users
Description: A group that includes all users that have logged on to a Terminal Services server. Membership is controlled by the operating system.

• SID: S-1-5-18
Name: Local System
Description: A service account that is used by the operating system.

• SID: S-1-5-19
Name: NT Authority
Description: Local Service

• SID: S-1-5-20
Name: NT Authority
Description: Network Service

• SID: S-1-5-32-544
Name: Administrators
Description: A built-in group. After the initial installation of the operating system, the only member of the group is the Administrator account. When a computer joins a domain, the Domain Admins group is added to the Administrators group. When a server becomes a domain controller, the Enterprise Admins group also is added to the Administrators group.

• SID: S-1-5-32-545
Name: Users
Description: A built-in group. After the initial installation of the operating system, the only member is the Authenticated Users group. When a computer joins a domain, the Domain Users group is added to the Users group on the computer.

• SID: S-1-5-32-546
Name: Guests
Description: A built-in group. By default, the only member is the Guest account. The Guests group allows occasional or one-time users to log on with limited privileges to a computer’s built-in Guest account.

• SID: S-1-5-32-547
Name: Power Users
Description: A built-in group. By default, the group has no members. Power users can create local users and groups; modify and delete accounts that they have created; and remove users from the Power Users, Users, and Guests groups. Power users also can install programs; create, manage, and delete local printers; and create and delete file shares.

• SID: S-1-5-32-548
Name: Account Operators
Description: A built-in group that exists only on domain controllers. By default, the group has no members. By default, Account Operators have permission to create, modify, and delete accounts for users, groups, and computers in all containers and organizational units of Active Directory except the Builtin container and the Domain Controllers OU. Account Operators do not have permission to modify the Administrators and Domain Admins groups, nor do they have permission to modify the accounts for members of those groups.

• SID: S-1-5-32-549
Name: Server Operators
Description: A built-in group that exists only on domain controllers. By default, the group has no members. Server Operators can log on to a server interactively; create and delete network shares; start and stop services; back up and restore files; format the hard disk of the computer; and shut down the computer.

• SID: S-1-5-32-550
Name: Print Operators
Description: A built-in group that exists only on domain controllers. By default, the only member is the Domain Users group. Print Operators can manage printers and document queues
.
• SID: S-1-5-32-551
Name: Backup Operators
Description: A built-in group. By default, the group has no members. Backup Operators can back up and restore all files on a computer, regardless of the permissions that protect those files. Backup Operators also can log on to the computer and shut it down.

• SID: S-1-5-32-552
Name: Replicators
Description: A built-in group that is used by the File Replication service on domain controllers. By default, the group has no members. Do not add users to this group.
The following groups will show as SIDs until a Windows Server 2003 domain controller is made the primary domain controller (PDC) operations master role holder. (The "operations master" is also known as flexible single master operations or FSMO.)

• SID: S-1-5-32-554
Name: BUILTIN\Pre-Windows 2000 Compatible Access
Description: An alias added by Windows 2000. A backward compatibility group which allows read access on all users and groups in the domain.

• SID: S-1-5-32-555
Name: BUILTIN\Remote Desktop Users
Description: An alias. Members in this group are granted the right to logon remotely.

• SID: S-1-5-32-556
Name: BUILTIN\Network Configuration Operators
Description: An alias. Members in this group can have some administrative privileges to manage configuration of networking features.

• SID: S-1-5-32-557
Name: BUILTIN\Incoming Forest Trust Builders
Description: An alias. Members of this group can create incoming, one-way trusts to this forest.

• SID: S-1-5-32-558
Name: BUILTIN\Performance Monitor Users
Description: An alias. Members of this group have remote access to monitor this computer.

• SID: S-1-5-32-559
Name: BUILTIN\Performance Log Users
Description: An alias. Members of this group have remote access to schedule logging of performance counters on this computer.

• SID: S-1-5-32-560
Name: BUILTIN\Windows Authorization Access Group
Description: An alias. Members of this group have access to the computed tokenGroupsGlobalAndUniversal attribute on User objects.

• SID: S-1-5-32-561
Name: BUILTIN\Terminal Server License Servers
Description: An alias. A group for Terminal Server License Servers.

• SID: S-1-6
Name: Site Server Authority An identifier authority.

• SID: S-1-7
Name: Internet Site Authority An identifier authority.

• SID: S-1-8
Name: Exchange Authority An identifier authority.

• SID: S-1-9
Name: Resource Manager Authority An identifier