Thursday, March 5, 2009

Password protecting Microsoft Word and Excel

Tip: Before password protecting any document, you may wish to create a backup of the non-password protected file in case you forget the password in the future.

Users who are creating a Microsoft Word or Microsoft Excel document that they wish to keep confidential or to only be viewed by people who should be viewing it may wish to enable a Microsoft Word or Excel password on the file to help protect the contents of the file. Below are the steps required for creating a Microsoft Word or Excel document with a password.

1.Open Microsoft Word or Microsoft Excel and the document you wish to password protect.
2.Click File
3.Click Save As
4.In the Save As window, click the Tools option in the upper right-hand side of the window.
5.From the Tools drop-down menu, select General/Security Options
6.This will open a Save window that will allow you to specify a password used to open the file and/or modify the file.

Password to open - Entering a password for this option will make the file only readable to the users who know the password.

Password to modify - Entering a password for this option will allow users to view the file but only edit and save the file if they know the password. Keep in mind, however, that a user could easily open the file, copy the contents of the file to another file, and modify and create their own document.

Monday, February 16, 2009

Try-finally block without catch

We use try-finally block without catch when we want our application to guarantee execution of cleanup code (in finally block) when execution of a block of code. If an exception occurs then the code in finally block will be executed before the exception is thrown to outside.

Consider below example:
void MyMethod1()
{
try
{
MyMethod2();
MyMethod3();
}
catch(Exception e)
{
//do something with the exception
}
}

void MyMethod2()
{
try
{
//perform actions that need cleaning up
}
finally
{
//clean up
}
}

void MyMethod3()
{
//do something
}
If either MyMethod2 or MyMethod3 throws an exception, it will be caught by MyMethod1. However, the code in MyMethod2 needs to run clean up code, e.g. closing a database connection, before the exception is passed to MyMethod1.

Wednesday, February 11, 2009

Instance versus Class variables/methods

1. Instance methods can access instance variables and instance methods directly.
2. Instance methods can access class variables and class methods directly.
3. Class methods can access class variables and class methods directly.
4. Class methods cannot access instance variables or instance methods directly—they must use an object reference. Also, class methods cannot use the this keyword as there is no instance for this to refer to