Monday, December 21, 2009

How to password protect an excel file in C#

If we need to protect an excel document with a password by some coding how will we do that? We may require to protect a report by some password after exporting it to MS Excel format. I'm going to demonstrate this by a Console Application with Visual C# code.

First create a console application and add a reference Microsoft.Office.Interop.Excel to it and just write the following piece of code. I've a standard excel file called "Test.xls".

Code:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

namespace MyConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string filePath = @"c:\Test.xls";
Application application = new Application();
try
{
Workbook myWorkBook = application.Workbooks.Open(filePath,
Missing.Value,
false,
5,
Missing.Value,
Missing.Value,
Missing.Value,
XlPlatform.xlWindows,
Missing.Value,
false,
false,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);

myWorkBook.Password = "koushik";
myWorkBook.Close(true, @"c:\Test2.xls", null);
Marshal.ReleaseComObject(myWorkBook);
}
catch (Exception ex)
{
application.Quit();
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}

Tuesday, June 2, 2009

My trip to Simla, Manali, Rohtang Pass and Delhi

We(me and my family) were planning for a trip this summer. After some discussion the route map was fixed. Decided that we would start with Simla followed by Manali and Rothang Pass and end it to Delhi where my elder sister stays. Started our journey on 16th of May 2009 by Kalka mail at 7.40 pm. Out of 7 members two (me nad my wife) boarded from Kolkata.


17th May(11.30 pm) - We reached Delhi station. Train was around 3 hrs late. My parents, elder sister, Jiju and my 13 years old nephew got into the train from there.


18th May(6.10am) - Finally the train got some momentum and reached Kalka station 1.5 hrs late. But the toy train from Kalka to Simla was scheduled to departure at 5.30 am. I was thinking what to do, because I thought the train was already left the station. Surprisingly found the train waiting for us!!! It was a nice small 1 boggy traing with 14 passenger capacity named by Rail Motor. Unfortunately I had 5 confirmed reserved seats and 2 waiting. After several requests the Ticket collector did not allow us(me and my wife) to board the train :-( . After that train's departure I did not get any reservation for two in any other toy train. So got into a passenger toy train which does not require any reservation and seats are available on first come first serve basis (lol...!!!). That train started moving at 8.30 am. With a pathetic speed with reached Simla after 6 hrs (normally toy trains take 4.5 to 5 hrs). But it was a nice experience regarding the scenic beauty and 103 tunnels that comes in between the journey. Here is a picture of that toy train.



(Toy train - Simla)


18th May (3.30 pm) -
We reached Simla. The car was waiting for us. After having some food we went to view some places of Simla. We went to Kufri, Green wall and some other places. Did some shopping in the famous Mall.



(Green wall - Simla)


19th May (8.00 am) -
We left out from Simla for Manali on road by a car. It took around 11 hrs from Simla. There is Kullu in between Simla and Manali. Due to road jam we had to avoid Kullu shopping center.



(Kullu)


19th May (8.30 pm) -
After reaching Manali we checked in the Hotel. It was Hotel Himangshu. A beautiful hotel with a charming lawn. The hills surrounded by snow were visible from there. We went out for a walk to see the local markets and the locality.



(Hotel Himangshu - Manali)

20th May (6 am) -
The car was ready. We got into it and started our journey to Rohtang Pass which is 51 km from Manali. It is 3979 meter / 13,051 feet high above the sea level. We just got spellbound after viewing the scenic beauty of it. The whole mountain range was covered by the snow. In winter the roads are used to be closed by the Indian Army. There was a great combination of cloud and snow at the peak of the mountains. They are kissing each other and sometimes being separated. But ice was melting and there was mud on the road. Anyway, finally we had selected a place and got down from the car. Enjoyed playing on and with the ice. The peak was very slippery. So had to get some stability while walking by the wooden stick which was available in rent. I was busy with my camera. The scenic view was changing very fast. It was very old over there and the cold wind was making our life tough. But forgetting the tough situation we were enjoying like anything! After spending around 3 hrs we had returned back to Manali. While returning back suddenly found some snow fall (wow! bonus!!!)... Before reaching hotel we had decided that we would visit
Solang valley. It was a nice small valley with lots of activities going around here and there like horse riding, free fall from the mountain while sitting in a big balloon etc etc... We did some horse riding so that we can view the whole place in quick time. After hovering around here and there we reached hotel.




(Rohtang Pass)


21st May (12 pm) -
We got ready, the packing was done and we are waiting for the car so that we could visit the local site scene and got into the bus for Delhi which was scheduled to leave from Manali at 3.30 pm. We visited many local sites of Manali. Went some temples and monastery too. Here is a picture of a monk who was not very pleased after I shot him with my camera.



( A monk - Manali)


22nd May (6.30 am) - We got down from the bus. It took around 14 hrs to reach Delhi. After that went to elder sister's house which took 1.5 hrs from there.

22nd May (1.30 pm) - We had our lunch and decided to visit some places of Delhi despite of having a very hectic journey which was continuing from some days. Anyway that didn't matter for us that time. We visited India gate, Raj ghat, Lotus temple and some other places.



(India Gate - New Delhi)


The next day (23rd May) we had our train to Kolkata. On 24th May we reached Kolkata and that's how our journey was ended. It was a very nice experience though the tour was very hectic. But surely it was a very memorable tour in my life till date.

You can view some more pictures of this tour on http://www.flickr.com/photos/koushikdas/

Happy traveling.
Cheers!
:-)

Tuesday, April 21, 2009

Project could not be opened because Microsoft Visual C# 2008 compiler could not be created

Did you face this problem in Visual Studio ever? When you open or create a new project then a error message come "Project could not be opened because Microsoft Visual C# 2008 compiler could not be created" followed by another error message like "QueryService for '{74946829-37A0-11D2-A273-00C04F8EF4FF}' failed."

If this error is buzzing you then there is an easy solution for this. First Close all Visual Studio instances that are presently running. Open Windows registry editor (run -> regedit) and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Packages. There you will find a Key called SkipLoading. Check the value, it must be 0x00000001. Change it to 0x00000000 and you are done.
Just restart the Visual Studio and enjoy...
Happy Coding...

Monday, February 23, 2009

In Love with my Sony H10 digital camera

Pheu... Finally grabbed a digital camera which suited my pocket. Its Sony DSC H10. More upgraded than a normal Point and Shoot camera. It's an extended zoom type camera with 10x optical zoom. I love the big 3" LCD screen for the clear view of the pictures. It supports a shutter speed of 1/2000 sec which is reasonable. I am also happy with 8.1 mp.
But something I dislike about it are: Focusing a object when I am in Macro mode, its tough to focus properly. Secondly the grains in the picture due to noise. I think Sony should care about it. Thirdly, the battery discharges soon. Actually the culprit is the big LCD screen which consumes much energy, though it runs on Lithium battery. Lastly the accessories are costly than the other company make camera like Canon, Kodak etc of its kind.
I know all products have some pros and cons. so taking it into consideration, I am happy with it for now.
For more details about this gear Click Here.

But but but.... when I see any DSLR or the pictures taken by it I used to drool... OMG! stunning picture quality and stunning performance. Don't know when I will be financially able to grab a DSLR, but I will definitely go for it one day! and for now my dream gear is Canon 450D.

Now let me share some pictures taken with Sony H10

#1




#2




#3


#4


and there's many more...

To see some others please go here : http://www.flickr.com/photos/koushikdas/


Thanks and Regards
Koushik