RSS

Visual Studio IDE Tips & tricks: ShortCuts for playing with blocks regions


How many times we get fed up of all the cluttered code? Best thing to do is put regions and collapse the regions to free up some space...

  • Fold/Unfold the current code block - Ctrl+M, Ctrl+M
  • Unfold all - Ctrl+M, Ctrl+L
  • Stop outlining - Ctrl+M, Ctrl+P
  • Fold all - Ctrl+M, Ctrl+O

Copyright © Shounak Pandit
0 comments

Posted in

How to have Multiple Instances of Project Server 2003 on 1 Machine


How to have Multiple Instances of Project Server 2003 on 1 Machine

How to have Multi[ple Instances of Project server on 1 Machine

I am using the following as examples throughout this article this will describe the steps needed to follow using EditSite tool by Microsoft:

SQL Server : Shounakp (my machine)

Database Name : ProjServer

Site name : ProjServer

Edit site tool : http://go.microsoft.com/fwlink/?LinkId=20891

    1. Copy the DATABASE directory – inside the support directory from your SQL 2002/ MS Project server installation CD, to the local drive on your SQL server (Server containing the ProjectServer DB).
    2. Create the new DB ( check fig below ) that will host your new Project Server instance in your SQL server. We need the file.
      NOTE: We cannot name the new instance DB as ProjectServer since the already existing instance of project server creates a DB named ProjectServer for use.

3. On your SQL server, go to command prompt and execute the following command from the Database directory.

4. In this case, is my SQL Server and using the account with password < pa$$@word1 >. The command will look like this : E.g

5. Hit ‘Enter”

6. The processing will take up few minutes let it finish properly (check the following screen)

7. The screen will look like the following screen shot, you will have to press any key to continue.

8. We need to grant permissions to the MSProject Roles on our new instance Database. Follow the steps

      • Open SQL Server Enterprise Manager
      • Click
      • Click
      • Double-click on MSProjectServerUser and grant permission to access the new Dataabse instance
      • Check and in the in ProjServer DB (the name of your new DB is) Tab.
      • Double-click on MSProjectUser and grant permission to access the new Db
      • Check and in the Dabase Roles in ProjServer (the name of your new DB is) Tab

See the following snap shot :-

9. Install the EditSite tool

10. Browse to C:\Program Files\Microsoft Office Project Server 2003 Resource Kit\Toolbox\EditSite and open the tool .

11. Click on “Add” in the Edit Site tool.A prompt will appear with focus on Tab (see folowing screen shot).

12. Enter the and In enter the name of your SQL server Machine managing your Session
in my case I used . Select “Default Web Site”, and any of the application pools. I selected MSPS2003AppPool.

13. Click on the Database Information tab and fill in the details.

    • Enter the name of your SQL server, the name of your new manually created DB (in my case I used ProjServer)
    • Enter the SQL user that has the MSProjectServerRole in ITProjects DB (in my case I used MSProjectServerUser with password “password”) and its respective password.
    • Do the above for the MSProjectRole Member (in my case I used MSProjectUser with password “password”.

14. Click on the

We need to use the same Sharepoint Services settings that we are already using for the 1st instance of Project Server
Hence we can get the WSS Settings from the 1st instance of the ProjectServer.

By following the path : Admin - > Manage Windows Sharepoint Services (See snapshot)

15. Click on Create of Edit Site tool You will get the message indicating that the new site was successfully created

16. Open IE and go to your new PWA instance. In my case, I go to http://shounakp/ProjServer

You will be given the following screen :-

17. Enter User name: Administrator and DO NOT enter a password. Hit “Enter”
You will see your newly created Project Server Instance and this message will pop up giving you the opportunity to change the PWA
Administrator’s password.


Change and save the password

18. Enjoy your newly created Project Server instance.

Cheers!!!!!

UPDATE: Reposting from my previous blog..

Copyright © Shounak Pandit


Visual Studio IDE Tips & tricks: ShortCuts for playing with blocks regions


How many times we get fed up of all the cluttered code? Best thing to do is put regions and collapse the regions to free up some space...

  • Fold/Unfold the current code block - Ctrl+M, Ctrl+M

  • Unfold all - Ctrl+M, Ctrl+L

  • Stop outlining - Ctrl+M, Ctrl+P

  • Fold all - Ctrl+M, Ctrl+O

Funny !! Marc Faber's comment on US Economy!!


Came across this comment from Marc Faber has gone back to the basics with his comment !!!
The federal government is sending each of us a $600 rebate.

If we spend that money at Wal-Mart, the money goes to China.
If we spend it on gasoline it goes to the Arabs.
If we buy a computer it will go to India.
If we purchase fruit and vegetables it will go to Mexico, Honduras and Guatemala.
If we purchase a good car it will go to Germany.
If we purchase useless crap it will go to Taiwan and none of it will help the American economy.


The only way to keep that money here at home is to spend it on prostitutes and beer, since these are the only products still produced in US.  I’ve been doing my part.

haha the funniest i think :))

to know more about Marc Faber visit his site: http://www.gloomboomdoom.com

Copyright © Shounak Pandit

Best frequency for code review... how to code review


Had an interesting discussion with a peer while coming back home..and it got me thinking..  he was complaining about the quality of code by his developers and was inquiring what approach I follow in my projects.

To tell you the truth I don't follow a specific time frame or frequency for performing code review.

Just to give you some food for thought
The frequency of code review should be directly proportional to the number of developers working on the project.

More the number of developers on a project more should be the code review frequency.just to give you a rough idea How many lines of code do we write in an hour? or in an day? we write lots of lines of code... multiplied by the number of developers is the lines of code you will have to review !!!!!!!

He was arguing about the time a PL/TL gets to do code reviews. well yes indeed he was right in his argument, we as PL's definitely do not get much time but who says we have to do code reviews every time till the release of the project?

The way the developers will write code in a project depends directly on the way they write code in the first couple of weeks of the start of the development phase.If you get them into the habbit of coding it right from the start of the project i guess we wont have to monitor much.

Of course that depends on the quality of the resource :)

The way i do code reviews is through automated tools & mentoring of good developers to perform code reviews on the team mates.

Naturally PL's dont get much time to get deeper into the code review process but yes all they have to do is

  • Identify the good resource who has a good style + approach at coding and mentor him/her to get into your shoes of performing code reviews.

  • Dont completely rely on that resource you do your surprise random code reviews.

  • Encourage peer reviews amongst the team. This will in turn ensure small coding issues get addressed at your subordinate level.

  • Utilize automated tools for code reviews there are loads of them in the market

  • There also are some preventive code review tools which get integrated into the VS IDE as a plugin and correct you with regards to naming convention/ style to a certain extent while you are writing code.Makes sense doesn't it? to be told what not to do while you are doing it rather than being told after you have already done it and moved on to the next piece of code.

  • Generate a check list for coding standards.


Copyright © Shounak Pandit

These are my views, my thoughts need not necassarily be the same as yours….. :)

Effective Code review or How to execute a Succesful code review


Code Review.... The dreaded words for a newbie ears ..or in most of the cases even for the experienced developers!!!!

How to code review ?
Over the years of being the code reviewer or me being the reviewee have noticed a few things which i feel are worth mentioning for an effective and pain free code review to happen.

What exactly is a code review i guess everybody knows that , ill try and point out some of the things which should be taken care of for a productive and pain free code review to happen.

  • Objective: Make sure the objective behind the code review is well known to the developers involved: Developers need to understand that the code is being reviewed and not the developers ability to code.



  • Coding Standard: Make sure you have a predefined set of coding standards circulated with the team before coding. Developers wont have any clue as to what you as a reviewer feel is the right coding standard unless they know what needs to be followed before they start coding.



  • Dont Accuse:Code review shouldn't be used to accuse the coder, but to point out the improvement areas in the code.



  • Ask / Discuss: Ask reasons for deviation that have happened than assuming: Its better to let the developers explain the reason for deviation rather than assuming.Lets face it many time there are some theoretically correct statements which cant be possible practically.Hence ask reasons for deviation, understand the developers thought process.



  • Listen: Remember the coding approach you use isn't like the ten commandments.Just because you feel reaching point C is better by going via point A not necessarily everybody will think the same.Let the developer explain why he felt going via point X was better as per him.



  • Understand: Remember the code review is about the coding style not about you.: Dont get offended if there are any improvement areas in your coding.Keep one thing in mind the person reviewing your code has also gone through the same phase as you currently.and till the time one understands the improvement areas we wont be able to improve and do coding expected by a seasoned developer.



  • Contribute: The coding standards wont contain all the development situations we face under the sun Hence contribution from the developer is absolutely necessary.Just because the person reviewing your code is a TL or PL doesn't mean he is right all the time.Express your view, understand the reasons why there are improvement areas.Keep one thing in mind we do those things best in which we believe in!!! hence if you do not understand why we are doing certain thing in a certain expected way you will never do it correctly so discuss and understand.



  • Appreciate: Code review isn't just about finding improvement areas. Utilize it also to appreciate someones coding style/Approach.


    Lets face it whether we like it or not we have to go in for code reviews some because their leaders make it mandatory while some because they understand the importance of code review.As long as code review happens in the right manner and for the right reasons it is always healthy for the complete team.

    Have seen or rather experienced developers who would argue over coding standard violation with pointless reasoning.reasoning that would be treated as childish excuses.Listen and explain to them anyways try and make them understand.Ofcourse in many cases you as a TL/PL need to put your foot down or do a little booting to make the developer sunderstand that crappy excuses wont be tolerated.

    Also one good thing to do beyond the coding standards document of what to do is to create a coding standard checklist for developers to check against as when they are coding.

    Copyright © Shounak Pandit

    These are my views, my thoughts need not necassarily be the same as yours.....

To Chrome or not to Chrome.. Google chrome features


Google has done it again… a product built on the problems of the browser users. 

To get a good idea about the features of the browser visit the features video site. The browser isn’t a complex browser Google  has stuck to its simplicity but effectiveness moto once again and delivered.

The Features list includes:

One of the best feature from the list above is the . This was the most awaited should have been implemented feature to be implemented in a tabbed browser.
How many times has one gone through situation where one had a hell lot of tabs/sites open in a tabbed browser and one of the site crashed and took the complete browser along with all the other sites down with it. kinda frustrating isnt it? and if you are like me you will have too many windows to multi task..
Google promises it has taken care of this by creating seperate sandboxes for each tabs. people developing code in the .NET environment will know what this is and how useful and a life saver it is. inshort each tab has its own seperate process to handle and service the requests.
Hence if one site/tab crashes the process related to that tab only crashes and not the complete browser process.

Heil Google!!!!

Another great feature implemented is the way the new tab opens.. it will open a tab with the most visited sites icons in it. All one has to do is click on the one of th emost visited sites. else there is also links on  the right hand side in the new tab to click on the new bookmarks added.

A pretty good and well though of feature..usually we visit some sites again and again like our mails, homepage etc which is easily accessible in front of us once we open a new tab.
One more worth mentioning but not on the features list is the <Chromes very own task manager>
It displays the CPU usage / Memory per tab and gives you the power to get rid / kill a rogue tab taking up memory /cpu time and slowing your machine.
To understand the tech behind Google Chrome go through the site explaining the technical details behind Google Chrome Its worth a Read.


© Shounak Pandit
0 comments

Posted in

Google Chrome the new hottie in the market ..


Google chrome just another browser or the mother of all browsers?

Google has done it again..another product/service in the market that has caught all the attention… yeah there are some negative feedbacks especially by the German media on the same too but hey whats success without some criticism??

The argument they have setup is pretty much the old stuff… personal data going to google with respect to the auto suggest feature explained more in detail here

 Google did bend to the criticism and declared they will anonymise the data within 24 hrs of collecting it..but the speculations will always be there..don’t understand the logic behind it… guys its a open source just dig into the source and satisfy your speculative minds ( if you are upto it :) )…. rather than just barking into the wind…

yeah its a bit risky giving a Beta to inexperience non techie users its like giving a child a Bazooka !! but am sure the Beta isn’t a actual Beta in the scientific terms its definitely a well tested and tried version of the product.we can trust google on this..

 

© Shounak Pandit

0 comments

Posted in

To Chrome or not to Chrome.. Google chrome features


Google has done it again... a product built on the problems of the browser users. 

To get a good idea about the features of the browser visit the features video site. The browser isn't a complex browser Google  has stuck to its simplicity but effectiveness moto once again and delivered.
The Features list includes:


One of the best feature from the list above is the <Crash Control>. This was the most awaited should have been implemented feature to be implemented in a tabbed browser.

How many times has one gone through situation where one had a hell lot of tabs/sites open in a tabbed browser and one of the site crashed and took the complete browser along with all the other sites down with it. kinda frustrating isnt it? and if you are like me you will have too many windows to multi task..

Google promises it has taken care of this by creating seperate sandboxes for each tabs. people developing code in the .NET environment will know what this is and how useful and a life saver it is. inshort each tab has its own seperate process to handle and service the requests.

Hence if one site/tab crashes the process related to that tab only crashes and not the complete browser process.

Heil Google!!!!



Another great feature implemented is the way the new tab opens.. it will open a tab with the most visited sites icons in it. All one has to do is click on the one of th emost visited sites. else there is also links on  the right hand side in the new tab to click on the new bookmarks added.
A pretty good and well though of feature..usually we visit some sites again and again like our mails, homepage etc which is easily accessible in front of us once we open a new tab.

One more worth mentioning but not on the features list is the <Chromes very own task manager>

It displays the CPU usage / Memory per tab and gives you the power to get rid / kill a rogue tab taking up memory /cpu time and slowing your machine.

To understand the tech behind Google Chrome go through the site explaining the technical details behind Google Chrome Its worth a Read.




© Shounak Pandit

Google Chrome the new hottie in the market ..


Google chrome just another browser or the mother of all browsers?

Google has done it again..another product/service in the market that has caught all the attention... yeah there are some negative feedbacks especially by the German media on the same too but hey whats success without some criticism??

The argument they have setup is pretty much the old stuff... personal data going to google with respect to the auto suggest feature explained more in detail here

 Google did bend to the criticism and declared they will anonymise the data within 24 hrs of collecting it..but the speculations will always be there..don't understand the logic behind it... guys its a open source just dig into the source and satisfy your speculative minds ( if you are upto it :) ).... rather than just barking into the wind...

yeah its a bit risky giving a Beta to inexperience non techie users its like giving a child a Bazooka !! but am sure the Beta isn't a actual Beta in the scientific terms its definitely a well tested and tried version of the product.we can trust google on this..

 

© Shounak Pandit

Code Review / Peer review.....


One wonders ....Why in the name of God would one want to spend (waste as some people say) time on performing a code review on any piece of code which we/peers have written and seems to be working properly and providing the functionality

I remember back then when i was an intern and i was assigned to a project in which my PM was a guy working in our US branch...people having worked with US bosses might be knowing thr are 2 types of techies our there... one who have less knowledge than you and the other lot who has so much knowledge than you that they make you feel like you are learning the alphabets of development while they are shooting out complex phrases after phrases of sentences....

man how i hated that guy i can still recall his words "Shounak, Dont even show me the functionality i dont care about it, first make sure you have it as per the coding standards" and i used to think what kind of a weirdo have i got as my boss ..he doesn't even want to see if the requirement has been met but cares about some stupid code review.....and i used to laugh at his code review obsession...

but over the years as i grew into a techie...into what they call a seasoned developer ..i realised the importance of code review
Code review isnt a tool to find mistakes in others code...its a tool by which one ensures the code is going to meet the standards expected of a seasoned developer.

There are various technical ways of achieving our requirements...or rather let me put it this way there are abundant ways of screwing up the way you meet your requirement.and there are some ways in which you meet the requirement in one of the optimum ways...and code review is a tool that helps us walk on the optimum path or close to the optimum path...



for an example check my post on string builder usage vs string concat... at String Builder Vs String concat/


Code reviews are important for a developer to understand how to keep improving his coding style ..


there are various good tools used for having automated code checking one that i have used extensively in my development days is FxCop and one more that i can't recall the name of...these were tools which would use the assembly n metadata as source and parse the assembly for any coding style /optimization errors


will try and write up about one of them soon



Cheers


© Shounak Pandit



Howdy Blogosphere!!!!


Have moved to this blog as my previous blog got deactivated :( due to lack of blogging !!!! have reposted all my posts from the other blog into here... and hope to blog quite frequently....

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level This error can be caused by a virtual directory not being configured as an application in IIS


Got the following error some time back when i tried running the project,



since it said that it wasnt configured to be dubugged i ran it with the good old "CTRL + F5" option and got the following error message in IE



my first guess after reading the error (make that reading half the error) was that somehow there was some configuration problem regardign who overrides whom in the web.config and the machine.config.

but after reading the Total error message understood that the error wasnt in the Web.config it was in the IIS virtual Directory settings that I had ,somehow it had changed.

Anyways, here is how to solve the error :-

Just open IIS and goto the properties for the Virtual directory and click on this button

How to have Multiple Instances of Project Server 2003 on 1 Machine


How to have Multiple Instances of Project Server 2003 on 1 Machine


How to have Multi[ple Instances of Project server on 1 Machine

I am using the following as examples throughout this article this will describe the steps needed to follow using EditSite tool by Microsoft:

SQL Server : Shounakp (my machine)

Database Name : ProjServer

Site name : ProjServer

Edit site tool : http://go.microsoft.com/fwlink/?LinkId=20891



    1. Copy the DATABASE directory – inside the support directory from your SQL 2002/ MS Project server installation CD, to the local drive on your SQL server (Server containing the ProjectServer DB).

    2. Create the new DB ( check fig below ) that will host your new Project Server instance in your SQL server. We need the <SETUPDB.CMD> file.
      NOTE: We cannot name the new instance DB as ProjectServer since the already existing instance of project server creates a DB named ProjectServer for use.







3. On your SQL server, go to command prompt and execute the following command from the Database directory.



4. In this case, <ProjServer> is my SQL Server and using the <SA> account with password < pa$$@word1 >. The command will look like this : E.g



5. Hit ‘Enter”

6. The processing will take up few minutes let it finish properly (check the following screen)





7. The screen will look like the following screen shot, you will have to press any key to continue.



8. We need to grant permissions to the MSProject Roles on our new instance Database. Follow the steps





      • Open SQL Server Enterprise Manager

      • Click <Security>

      • Click <Logins>

      • Double-click on MSProjectServerUser and grant permission to access the new Dataabse instance <ProjServer>

      • Check <Public> and <MSProjectServerRole> in the <Database Roles> in ProjServer DB (the name of your new DB is) Tab.

      • Double-click on MSProjectUser and grant permission to access the new <ProjServer> Db

      • Check <Public> and <MSProjectRole> in the Dabase Roles in ProjServer (the name of your new DB is) Tab






See the following snap shot :-





9. Install the EditSite tool

10. Browse to C:\Program Files\Microsoft Office Project Server 2003 Resource Kit\Toolbox\EditSite and open the tool .

11. Click on “Add” in the Edit Site tool.A prompt will appear with focus on <Site Information> Tab (see folowing screen shot).

12. Enter the <SiteName> and In <Session Manager> enter the name of your SQL server Machine managing your Session
in my case I used <shounakp>. Select “Default Web Site”, and any of the application pools. I selected MSPS2003AppPool.





13. Click on the Database Information tab and fill in the details.




    • Enter the name of your SQL server, the name of your new manually created DB (in my case I used ProjServer)

    • Enter the SQL user that has the MSProjectServerRole in ITProjects DB (in my case I used MSProjectServerUser with password “password”) and its respective password.

    • Do the above for the MSProjectRole Member (in my case I used MSProjectUser with password “password”.






14. Click on the <Windows Sharepoint Services Information>

We need to use the same Sharepoint Services settings that we are already using for the 1st instance of Project Server
Hence we can get the WSS Settings from the 1st instance of the ProjectServer.


By following the path : Admin - > Manage Windows Sharepoint Services (See snapshot)



15. Click on Create of Edit Site tool You will get the message indicating that the new site was successfully created

16. Open IE and go to your new PWA instance. In my case, I go to http://shounakp/ProjServer

You will be given the following screen :-



17. Enter User name: Administrator and DO NOT enter a password. Hit “Enter”
You will see your newly created Project Server Instance and this message will pop up giving you the opportunity to change the PWA
Administrator’s password.






Change and save the password

18. Enjoy your newly created Project Server instance.



Cheers!!!!!

UPDATE: Reposting from my previous blog..

Copyright © Shounak Pandit

Crystal Report toolbar images not Displayed ASP.NET


Reposting from old blog

One of my colleague faced a strange problem while using Crystal Reports

He got his report published on the ASPX page but the images in the toolbar weren't being displayed.
While trying to find out the problem for it I checked the ASPX page and noticed that the src path for the images on the toolbar was from another virtual directory  “crystalreportwebformviewer2” which to our surprise didnt exists on his machine at all.
Well no idea whether that was due to inapropriate installation or what but the fact was we didnt have a directory to which
t he images were being referenced from.

Well anyways here's the solution to the above problem
When you plan to use the Crystal reports toolbar in your reports it will automatically
refer to the images stored in your program files directory i.e


C:\Program Files\Microsoft Visual Studio .NET 2003\Crystal Reports\Viewers\Images



this directory has all the images in appropriate sub directories inside but for .NET to refer to it at runtime there
needs to be a virtual directory


in Our case the virtual directory being referenced was This might change according to the version of Crystal reports being used.

So all we had to do to get the Images on the toolbar was to

1# Create a virtual directory   crystalreportwebformviewer2
2# M
ap it to  C:\Program Files\Microsoft Visual Studio .NET 2003\Crystal Reports\Viewers\Images


After which the images on the toolbar were displayed without any other issue :)

Shounak Pandit

How StringBuilder string concatenation affects performance , string builder vs string concatenation "+"


reposting from older blog

How String Concatenation String Builder Append affects performance

Most of us have used String concatenation in our projects, Have we ever given a thought to what goes on behind while concatenating the strings?

There is a major flaw in using string concatenation as against the String builders append concerning performance only.
Except for performance and memory management both are same and give us the same desired output.

How they work


Lets take a look at how the things work when we concatenate strings

lets take a case where we are concatenating 2 strings and assigning the output to a 1st string

outputString += secondString;

In the above case, each instance of the string is created and assigned hence

in total we will have 3 instances of the strings!! Surprised?? well thats how strings concatenation works

It will create a new string outputString,with both old outputString and secondString

String objects in .net are immutable. Once the string has been created, the value can't be changed. When you type
outputString = outputString + secondString;
you actually discard the old outputString and create a new string object containing the result of the concatenation. When repeated several times, you end up constructing many temporary string objects.


now just imagine the case where you have n number of strings you have to concatenate how many string objects will be created wont that be a waste of time ??? Creating a string object assigning it some value then again creating a string object and so on .....

Imagine the impact on the performance of the application!!!!

Now lets see how String builder works

Using a string builder you will have



System.Text.StringBuilder outputString = new System.Text.StringBuilder();

outputString.Append(secondString);

StringBuilder, is a mutable string hence in this case we just have 1 instance of outputString and the second string is appended into that existing instance
no other instance is created hence the process is efficient and fast.


Note :- The point to remember here is that using StringBuilder for a concatenation of 2-3 strings doesnt make a significant difference in the performance but when you have numerous strings then the usage of StringBuilder has a big positive Impact on the performance

To see a example check my post

Shounak Pandit

Sending a Appointment programmatically through Code , ASP.NET ,ICalendar Format


Here is  in which you can send appointments via ICalendar format through code and not using the Outlook Object library (This is a very basic version of the way and does not involve much exception handling,and doesnt take care of nth case , explore a bit on that front :))



I am going to show the method of sending an appointment by creating a ICalendar Appointment file first and then sending it as an attachement over email.  (The way in which ICalendar format files are sent when you click on Tools ->Export -> as ICalendar file in the appointment )






Here is the declaration for the TimeFormat and some variables used to fill  the Appoinment details. viz start time,endtime etc.





const string c_strTimeFormat = "yyyyMMdd\\THHmmss\\Z";
string
strStartTime="";
string
strEndTime="";
string
strTimeStamp="";
string
strTempStartTime ="";
string
strTempEndTime = "";
string
vCalendarFile = "";

Create a Skeleton for the appointment ICalendar file format and using the variables created above we will assign the values accordingly into the Appoinment skeleton. (This string concatation can be optimised by using string builder)







// VCalendar Format.
const string
VCAL_FILE =
"BEGIN:VCALENDAR\n" +
"VERSION:1.0\n" +
"BEGIN:VEVENT\n" +
"DTSTART{0}\n" +
"DTEND{1}\n" +
"LOCATION;ENCODING=QUOTED-PRINTABLE:{2}\n" +
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{3}\n" +
"SUMMARY;ENCODING=QUOTED-PRINTABLE:{4}\n" +
"TRIGGER:-PT15M\n" +
"PRIORITY:3\n" +
"END:VEVENT\n" +
"END:VCALENDAR" ;



Assign the Appointment values to the variables declared in the first code section and in the appropriate format.








DateTime dtmStartDate = DateTime.Parse(startDate.ToString());
DateTime dtmStartTime = DateTime.Parse(startDate + " " + startTime.ToString());
DateTime dtmEndTime = DateTime.Parse(startDate + " " + endTime.ToString());
strTempStartTime = string
.Format("{0} {1}",
dtmStartDate.ToShortDateString(),dtmStartTime.ToLongTimeString());
strTempEndTime = string
.Format("{0} {1}",
dtmStartDate.ToShortDateString(),dtmEndTime.ToLongTimeString());
strTimeStamp = (DateTime.Parse(strTempStartTime)).ToUniversalTime().ToString(c_strTimeFormat);
strStartTime = string
.Format(":{0}", strTimeStamp);
strEndTime = string
.Format(":{0}",
(DateTime.Parse(strTempEndTime)).ToUniversalTime().ToString(c_strTimeFormat));

Using String.format fill in the Appoinment skeleton created earlier with the variable values.





vCalendarFile =
String.Format(VCAL_FILE, strStartTime, strEndTime, location, summary, subject , strTimeStamp, attendeeEmail.Trim() , "ShaunakP", attendeeName.Trim(), attendeeEmail.Trim(), organizerEmail.Trim());

Now that we have the ICalendar file created, we need to write it to the disk so as to attach it to the outgoing email
(Anybody knows a method of just creating the ICalendar file in memory and directly attaching the file without creating a Physical file please leave a feedback on how to do that,didnt get much time to look into it.)







filePath += "\\" + subject+ ".ics";
TextWriter tw = new StreamWriter(filePath);


// write a line of text to the file
tw.WriteLine(vCalendarFile.ToString());


// close the stream
tw.Close();

Now that we have the ICalendar all we need to do is send a mail to the persons involved in the Appoinment with the ICalendar file as an attachment.







// Create object for sending mails

MailMessage mail = new
MailMessage();
mail.To = attendeeEmail.Trim();
mail.From = organizerEmail.Trim();
mail.Subject = "You have got a Appointment.";

// create the attachment
MailAttachment attachment = new MailAttachment(filePath, MailEncoding.UUEncode);
// Attach
mail.Attachments.Add( attachment );
SmtpMail.SmtpServer = _smtpServer;
SmtpMail.Send( mail );

When the Person who receives the mail opens the attached ICalendar file,it will open up in Outlook as an Outlook Appoinment.

Cheers!!

P.S There are a lot of improvements that can be done in this code like for e.g using stringbuilder etc but I have skipped on them as this is just a code snippet.

To see the code for the above SendAppoinment method click here

*Update : For those of you interested in sending a Meeting Request here is the VCalendar format





"BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;CN=\"{8}\";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:{9}\n\n" +
"ORGANIZER:MAILTO:{10}\n" +
"DTSTART{0}\n" +
"DTEND{1}\n" +
"LOCATION:{2}\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:{6}\n" +
"DTSTAMP:{5}\n" +
"DESCRIPTION:{3}\n" +
"SUMMARY:{4}\n" +
"PRIORITY:5\n" +
"X-MICROSOFT-CDO-IMPORTANCE:1 \n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:-PT15M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR" ;



* Known Issue: If a person rejects the meeting it wont be conveyed to you

Datagrid Sorting ASP.NET or How to Sort Datagrid


Datagrid Sorting ASP.NET or How to Sort Datagrid


Step I )

In the Datagrid definition:
add 2 properties AllowSorting = true and OnSortCommand="MethodName in code behind"


e.g
<asp:datagrid id="dgSearchList" runat="server" Height="125px" Width="627px" CssClass="panelChildSolidBorder"
CellPadding="2" AllowCustomPaging="True" AutoGenerateColumns="False" OnItemCommand="detailsClicked"
ShowHeader="True" AllowSorting="True" OnSortCommand="dgSearchList_SortClick" PageSize="4">

AllowSorting="True"
makes the datagrid sortable and OnSortCommand="dgSearchList_SortClick" tells which method to call when the header is clicked.


Step II )

Now we need to define the method to call when the column headers are clicked
here dgSearchList_SortClick is the method that will be called when the Column headers are clicked for sorting.

Codebehind :

public void dgSearchList_SortClick(object sender,DataGridSortCommandEventArgs e)
{
sortField = e.SortExpression; // ie the Sortexpression assigned to the Column.Check STEP III for how to assign a   // sortexpression on a column.
PopulateDatagrid(); //Call the method that populates the Datagrid with
//the values from the Dataview.
}

PopulateDatagrid()
{
if(sortMode.ToString().Trim().Equals(SORT_ASC))
{
sortMode = SORT_DESC; // Here sortMode is just a Variable storing the
direction of the sort.There are better ways to store this than the current one shown hereJ
}
else
{
sortMode = SORT_ASC;
}
txtSortMode.Text = sortMode;

// SORT_DESC and SORT_ASC are constants with the following string values.
// SORT_DESC = “Desc”
// SORT_ASC = “Asc”

DataView dv = new DataView(dt);
dv.Sort = sortField.Trim() + " " + sortMode;
dgSearchList.DataSource = dv;
dgSearchList.DataBind();

}

The code above checks whether we want to sort in Ascending order or in Descending order
and assigns the SortExpression concatenated with the Sorting direction (Asc/Desc)
and binds the datagrid again (don’t forget to bind the data grid its very important)


Step III)
You need to specify the sorting expression for that column in the column definition in the ASPX page

e.g
<asp:BoundColumn DataField="Location" SortExpression="Location" HeaderText="LocationArea">
<ItemStyle Height="10px" Width="10px"><!--ItemStyle>
asp:BoundColumn>


be carefull of what you define as the sortexpression because this is what is passed to the codebehind and sortexpression is what identifies which column was clicked for sorting

in this case the sort expression for the LocationArea column is “Location”, hence when we clicking on the location column will set the e.SortExpression (check Step III for e.SortExpression) to “Location”. Hence identifying the column clicked.

First Web Service :) used XSLT for transforming XML


Worked on my first Web Service today, wasn't much of a complex web service but I got some idea about WebServices and their working.
Was a simulation of a XML returned by a third party tool retrieving records from DB2,
The objective involved getting rid of the extra nodes (data) returned in the XML from the 3rd party and just passing on the XML data recognised by the consumer application as a valid object.This was achieved by making my transformer app sit in between the Webservice and the consumer app.


The best option in this case was transforming the XML output from the 3rd party tool into XML recognised by the consumer application using XSLT as it allowed us to change the nodes (data) passed on to the consumer app by just changing the XLS file and not recompiling the whole of the transformer app (incase we had written a custom class to take care of parsing the output XML and returning only selected number of fields).
Will post a code snippet on the transformation code a bit later.Now I am almost done with the Cruisenet Doc ,will be posting that in a while here (by tomorrow most probably) and ofcourse the Nant and Nunit doc need to be completed and posted too :)

Visual Studio IDE Tips & tricks: ShortCuts for formating code , commenting code , wordwrap code


ShotCut Keys

Convert selected code to lower case - Ctrl+U
Convert selected code to upper case - Ctrl+Shift+U
Comment selected code - Ctrl+K, Ctrl+C
Uncomment selected code - Ctrl+K, Ctrl+U


WordWrap

Have a line of code which goes beyond the screen width? but you need to keep it that way and the only alternative is to scroll all the way to the right?
Well theres good news VS IDE provides a (toggle) shortcut which will put the line contents beyond the screen width on the next line and back onto the same line.


ShortCut Key : - Ctrl + r + r (toggles)

Visual Studio IDE Tips & tricks: Bookmarks & Incremental Search


Bookmarks

Bookmarks are available through Edit - > Bookmarks.
using bookmarks we can mark places in our code which we would like to revisit later on.
Create/Remove Bookmark - Ctrl+K, Ctrl+K
Move to next bookmark - Ctrl+K, Ctrl+N
Move to previous bookmark - Ctrl+K, Ctrl+P
Clear all bookmarks - Ctrl+K, Ctrl+L


Incremental Search Pressing

Ctrl+i will incrementally search for text as you type.

HOWTO : Press Ctrl + i then type the word you want to search. Hit backspace to clear a character and enter to finish.
Pressing F3 after this will work as usual, i.e. search for the next occurrence of previous search.

Response.Redirect Try catch block , ThreadAbortException


What is with the combination of Response.redirect and Try catch block?



well, most of you who have tried out the combination must have been stuck with a weird error of "Thread was being aborted" and must have wondered what has a thread got to do with Response.redirect?



Well, to answer your question here goes:-

A thread is executing your application in terms of ASP.NET worker process , when you call Response.Redirect(URL);

In your code then to redirect to the new URL specified by you ASP.NET framework must be told to stop the current execution of the page and to transfer the execution to the URL page specified in the method call.

This is done in a 2 way step :-

1) Response.End() is called internally by Response.Redirect to stop the current execution and the ThreadAbortException is thrown.

2) .NET framework will call catch “ThreadAbortException” and stop current execution and start executing the new page.

Now during the Step #1 Response.End will throw out a ThreadAbortException” to let .NET framework know that the current execution needs to be stopped and the execution of new should begin.

Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of to be redirected page.



Solution :- The way to get over this problem is to specify Response.Redirect(URL,false) , this will tell .NET framework not to stop the execution of the current thread and hence the error will be resolved.

ThreadAbortException” is a special kind of an exception even if you catch it in a catch block even then it will be raised again at the end of the catch block. When this exception is raised, the runtime executes all the finally blocks before killing the thread.
Copyright © Shounak S. Pandit. Powered by Blogger.

Ads