Friday, May 19, 2006

Moving My Blog

I've moved to http://www.geekswithblogs.com/rajiv - this blog exists purely for my own refrence now - all new entires will be posted at the new blog.

Wednesday, December 28, 2005

Sharepoint and Email... Am I Missing Something?

Well, It's been quite some time since we went on a 'considerable' sized Sharepoint implementations and honestly speaking I do feel Sharepoint is a GREAT tool when it comes to collaborating within project teams.

One of the BIGGEST limitations I've had to work around however is the inability to send automated emails to users. Alerts though present are very different; because a user needs to sign up for his own alerts and manage them himself. On the other hand forced emails sent to the person in the "Assigned To" column is only a function of the issue list and as far as I realized most of this code is in Camel and not open source so it's pretty ugly to use an issue list for all scenarios just to utilize this email feature.

We've been working around this using multiple approaches - some of which are:

  • Have JavaScript functions which are invoked on certain events firing - these functions just link using "mailto://" protocol and works like a charm for basic emails.

  • Another idea I had was to have a ASP.NET component that uses Mail APIs to send mail. This could be invoked by web parts and parameters could be passed to it using query string. To generate Meeting Request the component could generate ICS files and then send them to the users.


Any better ideas or approaches, Anyone? Am I missing something here? Does Sharepoint have any out of the box solutions for emails when a list (which is NOT an issue list) is updated?

Wednesday, November 16, 2005

Cool File Functions in .NET 2.0

For A Recent Project I had to extract BLOBS stored in DB and write them in the file system. Turns out, there is a cool file system function which just lets you write an entire byte array to disk!!

byte[] bFile = new byte[filesize];
bFile = (byte[])ds.Tables[0].Rows[nCounter]["FILE_DATA"];
System.IO.File.WriteAllBytes(fileURL, bFile);

The WriteAllBytes is an out of the box function that just takes the file path and name along with the byte arrary and just creates the file for you IF the directories specified in the path exist. Cool huh?

Wednesday, November 02, 2005

Thinking About Generics

A comment on my post on generics had me thinking - the question was simple - So, are generics just custom lists or are there any more uses I can think of? I thought it would be good to pause a little and think on what generics are to answer this question. Here's what i think (I am no expert on generics though:) )
Basically, Generics are a nice way of creating flexible data structures or type safe classes. The basic idea is that we implement the class that providers service in a 'generic' way. A Crude example... Public Class People <T> ... considering that <T> could be a student, friend, relative.... Now we can basically have the methods within the People class essentially work for students, friends and relatives as long they use algorithms with depend on common attributes of all these objects. Possibilities? Unlimited. All arguments are welcome :)

Monday, September 12, 2005

Using XmlTextReader to read XML from Text Variables

For those who have used the .NET XMLTextReader - they will be well aware that is lets you load the xml file and then read through the nodes and attributes. Recently I faced a painfull situation when my XML was in a plain simple sting variable instead of a file. I though of loading it into a Stream and passing it to the XMLTextReader and a 100 other crappy solutions till this one looked most elegant and worked!

ds.ReadXml(new XmlTextReader(new StringReader(myStringWithXml)));
[Where ds is the instance of my XMLTextReader]

This User Group provides more information

Sunday, September 11, 2005

Exciting Times…

Besides having to spend a lot of time in J2EE / XSL projects lately… I’ve been coding away on an open source .NET project (during my late nights) for the past few days just to make sure I don’t miss out the Exiting Beta 2 Learning Times of the .NET world!

Beta 2 has been a Dream come true for me all the way! In fact the entire .NET world seems to be maturing so VERY fast! A couple of days ago I went hunting for OR (object Relational) frameworks in .NET and to my surprise I found over 10 of them to choose from! I settled for nHibernate (I understand Microsoft is developing ObjectSpaces whose’ release has been delayed till Long Horn release).

As I coded away I faced a few problems e.g. converting nHibernate classical lists to Generics. Again to my surprise I found quite a few articles in news groups where people had already tired similar things and had ideas on how to achieve this. I posted my questions and by the next day I had an answer from a MVP in my inbox! The guy is now helping me review my code and hopefully will come up with few more suggestions and enhancements.

What really excites me is not just features in Visual Studio 2005 (yes, Generics, Auto Generations of class diagrams and their auto update features, Refactoring, Code Snippets, Templates are AMAZING features) but what is really exiting about this times is the people who are getting involved in the Microsoft World!

There are TONS of REALLY SMART guys writting open source frameworks like nHibernate... There are authors who reply to you! MVPs who go out of their way to answer your questions and articles out there that teach you everything without a dime! These are REALLY exciting times.

Friday, July 08, 2005

Some more 'HOT' features of studio 2005

The Beta has been driving me nuts! it's a dream come true for any Developer. Here are some more really HOT features to watch out for:
- Code Snippets - Sleek and smart!!! The way the snippets are inserted is cool but what really blew me off was the way varaible names changed when i changed specific part of the pre-insterted template!
- Refactoring - Some mind blowing features here. What i like most if i no longer need to type the same lame code to create properties.
- Partial Classes - Sleek and neat organization of code. Now two of us could be working on the same class at the same time but still stay on seperate files without worrying about screwing up each others work. The only thing that made me knit a brow slightly was the fact that i had to declare all my fields in a single file or else studio kept firing a warning. hmmm... must be some reason behind it i cant catch.

Custom Classes are NOT Value Types...

This is for all the confusion that is often caused due to a commonly made mistake all of us make at some point of time - Classes are NOT Value types! In other words when you assign an object of a class to a variable you are assigning a reference and not a 'copy' of the value! So, basically a change in either one of the objects now reflects in both. Followin Code snippet illustrates:

Employee rajivpopat = new Employee();
rajivpopat.EmployeeName = "rajivpopat";
rajivpopat.EmployeeDOB = System.Convert.ToDateTime("11/24/1981");
rajivpopat.AdditionalContactDetails = "AdditionalDetails";

Employee chetanpopat = rajivpopat;
chetanpopat.EmployeeName = "chetanpopat";
MessageBox.Show(rajivpopat.EmployeeName);
This shows and output "chetanpopat" - because change of chetanpopat.EmployeeName = "rajivpopat" has changed the vallue that rajivpopat.EmployeeName was referencing!!!

Structs however, work with a different concept and are Value Types! The Same code would return "rajivpopat" if Employee was defined as a struct! You'll not be able to initialize values of fields in struct and they will all be initialized by default value!!!

Thursday, June 23, 2005

Generics in Visual Studio.NET 2005

Features Of Visual Studio 2005.NET Beta 2:
Struck by the sheer amount of time some of us have wasted by not playing around with Visual Studio.NET 2005!!! For the next few days I'll be publishing all new features of Visual Studio.NET 2005 as I play around with them. After installing Visual Studio.NET 2005 (and NOT being able to install MSDN Locally!) Generic Classes was the first thing I could lay my eyes on. I quickly wanted to write up a Generic Class and understand what I can and cannot do with them! The Below code snippet attempts to describe:
When Would I use Generic Classes?
From what I gathered I Would use Generics when I want a Type to accept any Generic Type and perform action on it! This requires some code to explain (the MSDN Code of Linked List implementation was slightly complicated):

/// <summary>
// Takes Any Generic Class.
/// </summary>
/// <typeparam name="T"></typeparam>
public class CurrentObject<T>
{
private T data;
/// <summary>
/// return the added object of the class to the calling program.
/// </summary>
/// <returns></returns>
public T returnObject()
{
return data;
}
/// <summary>
/// Allows addition of object of that Generic class
/// </summary>
/// <param name="objectData"></param>
public void AddObject(T objectData)
{
data = objectData;
}
}
 

The first thing we do in the above snippet is Create a class called CurrentObject which can accept any Generic Class as a parameter. Once we have accepted a type we create an object of the type accepted in the first line of the class.
We now introduce two new methods returnObject and AddObject. AddObject allows me to pass an object of the class I declared earlier. Once we have the object we just assign it to the object we created internally in the CreateObject class. In return Object we just return the class.
Lets take a quick preview of how we use this Generic Class. First thing we do is we create a quick class with two field that we will use with this Generic Class that we created!

/// <summary>
/// A Class That Will be passed to the Current Object object
/// </summary>
public class Customer
{
public string CustomerFirstName = "";
public string CustomerLastName = "";
}
Now the interesting part:
static void Main(string[] args)
{
// Create and Instance Of CurrentObject Generic Type
CurrentObject<Customer> currentCustomer = new CurrentObject<Customer> ();
Customer tmpCustomer = new Customer();
tmpCustomer.CustomerFirstName = "rajiv";
tmpCustomer.CustomerLastName = "popat";
// The Below could be a complex Linked List or Similar Implementation!
currentCustomer.AddObject(tmpCustomer);
Customer finalCustomer = currentCustomer.returnObject();
// Print the results obtained from the Generic type!
Console.WriteLine("Customer First Name is : " + finalCustomer.CustomerFirstName);
Console.WriteLine("Customer Last Name is : " + finalCustomer.CustomerLastName);
Console.ReadKey();

}

We create an object of CurrentObject Generic class by passing the Customer class to it. Then we use another customer object that we have and pass it to the AddObject Method. (This is the method which could have been as complicated as we want based on the logic of the collection that we are developing!) The returnObject finally returns the object and assigns it to finalCustomer. Again, it is to be noted here returnObject could return any object of the same class based on the complex logic of our collection!!!

So basically the same collection we design works for virtually ALL classes and types!!! MIND BLOWING!!!

Wednesday, June 22, 2005

Uninstalling Visual Studio.NET 2005 Beta 1

This link talks about uninstalling Visual Studio.NET 2005 (Beta 1) so that you can move on to better things in life (Beta 2). Some really useful tips here, namely...

If you see an error removing J# .NET Redistributable Package 2.0 from Add/Remove Programs, please run "msiexec /x {9046F10C-F5E7-4871-BED9-8288F19C70DF}" from a command line window

If you see an error removing .NET Framework 2.0 from Add/Remove Programs, please run "msiexec /x {71F8EFBF-09AF-418D-91F1-52707CDFA274}" from a command line window

Even if there were no errors and the Beta 2 keeps complaining that you have old J# Redistributable and Framework 2.0 still present in your computer EVEN after removing these from Add / Remove Programs the above tips are basically life savers!

Tuesday, June 07, 2005

Validating Date inputs for specific format.

There are times when we need to trap date input and see if the value is a valid date or not. the usual approach to this is to use DateTime.Parse and then trap exceptions. if there is an exception we assume that the date entered is not valid. however there are also times when we need to trap exact format in which the date entered. e.g. we want the user to enter 02-24-1995 5:00 and NOT 02/24/1995. The code snippet illustrates how this can be done.

System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.LongDatePattern = "MM'-'dd'-'yyyy HH':'mm";
try
{
DateTime dt = DateTime.ParseExact("02-24-1995 5:00","MM'-'dd'-'yyyy HH':'mm", dtFormat);
}
catch(Exception ex)
{
MessageBox.Show("The Following Exception Was Trapped While Validating Date:" + ex.Message);
}