Monday, March 24, 2008

Set security access to folder

I'm currently doing a small function, where I need to create folder dynamically, if the folder does not exist.

Creating folder is easy, but I also need to set the security access. Finally, I've found the way of doing this. Happy

I have created a simple class to perform this Directory-related tasks, named "Folder".

Firstly, we need to include System.IO (for Directory class) & System.Security.AccessControl (for FileSystemRights & AccessControlType enums).

public static bool Exists(string folderPath)
{
return Directory.Exists(folderPath);
}

public static void Create(string folderPath)
{
Directory.CreateDirectory(folderPath);
}

public static void Delete(string folderPath)
{
Directory.Delete(folderPath, true);
}

public static void AddSecurity(string folderPath,
string userAccount,
FileSystemRights fileSystemRights,
AccessControlType controlType)
{
DirectoryInfo folderInfo = new DirectoryInfo(folderPath);

DirectorySecurity folderSecurity = folderInfo.GetAccessControl();

folderSecurity.AddAccessRule(
new FileSystemAccessRule(userAccount, fileSystemRights, controlType));

folderInfo.SetAccessControl(folderSecurity);

}

public static void RemoveSecurity(string folderPath,
string userAccount,
FileSystemRights fileSystemRights,
AccessControlType controlType)
{
DirectoryInfo folderInfo = new DirectoryInfo(folderPath);

DirectorySecurity folderSecurity = folderInfo.GetAccessControl();

folderSecurity.RemoveAccessRule(
new FileSystemAccessRule(userAccount, fileSystemRights, controlType));

folderInfo.SetAccessControl(folderSecurity);

}

public static string[] GetListOfFileSystemRights()
{
return Enum.GetNames(typeof(FileSystemRights));
}

public static string[] GetListOfAccessControlTypes()
{
return Enum.GetNames(typeof(AccessControlType));
}



Function: If the folder does not exist, create it and set security access.




if (Folder.Exists(folderPath) == false)
{
Folder.Create(folderPath);
Folder.AddSecurity(folderPath,"MY\\CHONGLK", FileSystemRights.Modify,AccessControlType.Allow);
}



 


To remove the security access for certain rights, use the RemoveSecurity method:



Folder.RemoveSecurity(folderPath,"MY\\CHONGLK", FileSystemRights.Modify,AccessControlType.Allow);



The last two functions is to allow users to bind the list of enum values to the UI control.




//List all FileSystemRights values in dropdownlist
systemRightsDropDownList.DataSource = Folder.GetListOfFileSystemRights();
systemRightsDropDownList.DataBind();

//List all AccessControlTypes values in dropdownlist
controlTypeDropDownList.DataSource = Folder.GetListOfAccessControlTypes();
controlTypeDropDownList.DataBind();



It's quite simple, but I didn't know these methods before this. Tongue At least, I learnt something new.

Friday, March 21, 2008

List out all enum values

I just found out the way to list out all the enum values. It's indeed very simple!

For example, I want to list out all the enum values of FileAccess.

string[] enumList = Enum.GetNames(typeof(FileAccess));
DropDownList1.DataSource = enumList;
DropDownList1.DataBind();



I also found out how to convert the string representation value to the enum value too.



FileAccess fAccess = (FileAccess)Enum.Parse(typeof(FileAccess), DropDownList1.SelectedValue);



that's it. Isn't it simple?

MCPD: Learning Plan for Exam 70-536

URL: http://learning.microsoft.com/manager/LearningPlanV2.aspx?resourceId=%7ba3e18fcd-60ed-489b-94d6-4c30e1bf9542%7d&clang=en-US

You may also sign in to Micrsoft Learning to look for any learning resources, including the learning plan. You also also track your learning here.

In this learning plan, there are recommended learning resources, where you can follow them step by step until you reach the stage of registering for the exam.
I plan to follow this learning plan to start my learning process for Exam 70-536, then I'll see what extra resources I need when time goes by.

MCPD: Preparation Guide for Exam 70-536

URL: http://www.microsoft.com/learning/exams/70-536.mspx

This will be my first paper:
Exam 70-536 [Microsoft .NET Framework 2.0 - Application Development Foundation]

From the link above, you'll find these information:
- Exam news
- Exam topics covered
- Audience profile
- Credit toward certification
- Code languages
- Prepartion tools and resources
- Skills measured

I guess the most important is the skills measured section. You'll be told in detailed what knowledge are required in order to take the exam. You can use the long list to measure your knowledge.

I just jot down the keywords for exam topics covered in this paper:
1) system types & collections
2) service processes, threading, application domains
3) embedding configuration, diagnostic, management, and installation features
4) serialization & I/O
5) security
6) interoperability, reflection, mailing funcitonality
7) globalization, drawing and text manipulation

MCPD: Exam Question Types

Information extracted from: http://www.microsoft.com/learning/mcpexams/policies/innovations.mspx

I've found this site when I was looking for the information regarding MCPD.
There are several types of exam questions. It may be good if we get ourselves familiar with these types:

1. Hot area questions
This kind of question asks you to indicate the correct answer by selecting one or more elements within a graphic.

2. Active screen questions
This kind of question asks you to configure a dialog box by changing one or more elements.

3. Drag-and-drop quetsions
This kind of question asks you to drag source objects to appropriate targets within a work area.

4. Build list and reorder questions
This kind of question asks you to indicate the correct answer by building an answer list.
In a build list and reorder question, you need to build a list by dragging the appropriate source objects to the answer list and then placing them in the correct order based on criteria defined in the question.

5. Create a tree questions
This kind of question asks you to create a tree structure.
You indicate the correct answer by dragging source nodes to the correct locations in the answer tree.
Nodes consist of text and a small icon.

6. Testlet exam format

7. Windows 2000 simulation questions
This kind of question asks you to indicate the correct answer by performing specific tasks such as configuring and installing network adapters or drivers, configuring and controlling access to files, and managing hardware devices. (This seems to be more applicable for System engineering exams)

You may download the MCP Exam Demos too, then you'll understand better what the aboved question types mean. It's quite fun to run through the exam demo. ^_^

MCP Test Demo
There is an "Instructions" button to tell you what type of question it is, and how you should respond. A "Calculator" button is provided too.

Wednesday, March 19, 2008

MCPD - Start the Journey

MCPD
I have been thinking of taking this certification - MCPD (Microsoft Certified Professional Developer) for quite long. Well, actually I have been thinking since MCSD (Microsoft Certified Solutions Developer), then it changed to MCAD (Microsoft Certified Application Developer). Finally, there came a new generation again.
Finally, I've made a move - we've bought several books yesterday.
Perhaps this time, I'm really going to pursue this cert, because the company is sponsoring. haha~~

My boss has been asking us to look for external courses, and I think pursuing MCPD is a good idea. We've calculated the price of the books we are going to purchase, altogether 7 books, for 3 papers, cost us RM1600. It'll be a burden for me to spend this amount of money just on the books only. As the courses are too expensive, say RM2400 for 3 day course, that is RM800 for a day, RM100 for an hour. We've decided to study by ourselves, and we'll also see if there are any useful or interesting courses, then we can subscribe for them too. Perhaps we'll go for those topic-oriented courses, instead of going for the certication ones.

I wish I can spend one hour per day to study on this. Perhaps reading the books, doing some research online, taking some sample tests. See how it goes.

The papers I'm required to take are as follow:
1) Exam 70-536: Microsoft .NET Framework 2.0 - Application Development Foundation
2) Exam 70-528: Microsoft .NET Framework 2.0 - Web-Based Client Development
3) Exam 70-547: Designing and Developing Web Applications by using Microsoft .NET Framework


My first paper will be Application Development Foundation. I need to go and check out any resources for this MCPD, and hope to know anyone who's also taking or already taken this cert. ^_^

More to find out soon...... I gotta keep myself motivated. haha~~

Reference:
* MCPD Official website