Me Myself & C#

Manoj Garg’s Tech Bytes – What I learned Today

Archive for July, 2007

Google Picasa with Maps

Posted by Manoj Garg on July 19, 2007

I am a big fan of Google and its products. Each one of its product is much better then its competitors (at least this is what I think smile_wink), be it Gmail or Picasa or Google maps etc. all are best when it comes to usability. 


I have been using Picasa since long. It has got lots of good image categorization and editing features, what a good image editor should have. Recently it came up with a feature of “Web Album” where you can store your images online and then do a slide show or organize them in a folder etc. So what’s new with Picasa? Now they have integrated it with Google maps, so you can tag each picture with a map with it, which will tell the viewer exactly where you took that picture.

So how do one associate a map with his/her picture. Basically its very simple.

  • Select an album,
  • then use the ‘Map Photos’ button to map a/all pictures.

lightbulb You can map a complete album with a location.

Posted in Picasa | Tagged: , , | 2 Comments »

Truncating Transaction Log in SQLServer 2000

Posted by Manoj Garg on July 17, 2007

Few days back I had a situation when size of my database transcation log was growing too  fast (at a point it reached 60 GB). so I had to find some way to truncate it to some minimal size. After lot of googling, I found how to truncate the transaction log.

Run these two commands in Query Analyser.

  2. DBCC SHRINKFILE(<<DBName>>_log, <<Desired transaction filesize>> )

Remarks :

  • DBCC SHRINKFILE applies to the files in the current database. If you try to  run this command in a different DB then the DB you want to shrink, SQL Server will give following error

Server: Msg 8985, Level 16, State 1, Line 1
Could not locate file ‘<<DBName>>_log’ in sysfiles.

  • SQL Server uses <<Desired transaction filesize>> to calculate the target size for the entire log; therefore, target_size is the amount of free space in the log after the shrink operation. Target size for the entire log is then translated to target size for each log file. DBCC SHRINKFILE attempts to shrink each physical log file to its target size immediately. If no part of the logical log resides in the virtual logs beyond the log file’s target size, the file is successfully truncated and DBCC SHRINKFILE completes with no messages. However, if part of the logical log resides in the virtual logs beyond the target size, SQL Server frees as much space as possible and then issues an informational message. The message tells you what actions you need to perform to move the logical log out of the virtual logs at the end of the file. (Remarks are taken from MSDN)


  1. Microsoft Knowledge Base (KB272318)
Ha-P Querying 🙂

Posted in Database, MS SQL Server 2000 | Tagged: , | 3 Comments »

Using Predicates with List.Find()

Posted by Manoj Garg on July 16, 2007

Yesterday, One of my team member had a requirement for searching a List for an object having a specific value for one of its member. After some googling I found out few links explaining use of Predicates for this kind of custom searching. It solved my purpose.. so here goes how I did it 🙂

For example, we have a class Employee with members like EmpCode, First Name , Last Name etc.

public class Employee{    
    //Private members for all the below described properties
    //Public Properties   
    public String EmpCode;    
    public String FirstName;    
    public String LastName;    
    public DateTime DateOfBirth;
    public String Department;
    public String Designation;

    public Employee(String ecode, String fname, String lname, DateTime dob, String dept, String desg)
         EmpCode = ecode;
         FirstName = fname;
         LastName = lname;
         DateOfBirth = dob;
         Department = dept;
         Designation = desg;    
and we have a list of Employee objects..

public class EmployeeList : List<Employee>
{ }

Now suppose we have a list of employees and we want to search them on the basis of their first name. There are two ways to do it.

  1. we iterate through the complete list and compare each Employee object’s FirstName property to our required value
  2. Or, we can use predicates to search the intended objects.

Following code snippet shows how to use predicate in List.Find() method

EmployeeList elist = new EmployeeList();
elist.Add(new Employee("1","Mk","Garg",DateTime.Now,"ITG","Arch"));
elist.Add(new Employee("2","P","Jain",DateTime.Now,"SE","Engg"));
elist.Add(new Employee("3","A","Goyal",DateTime.Now,"QA","Lead"));
elist.Add(new Employee("4","Bob","Matt",DateTime.Now,"HR","Mgr"));

//Find Using Inline
Employee em = elist.Find(delegate(Employee e) { return e.FirstName == "Mk"; });

Here in the above code em will have the Employee object with FirstName = “Mk”

Output will be

Prdicate example output 

These predicates can be used as annonymous functions as we used in the above code function, or  we can define a function which accepts an Object of type, we want to search, as parameter, and it returns bool value indicating whether a record mathed the criteria specified. it is a static method.  For example, in our code suppose we want to search the employees by their designation we can do it like :

Employee edesg = elist.Find(FindByDesignation);

Here FindByDesignation is a method which looks like:

private static bool FindByDesignation(Employee e){return (e.Designation == “Lead”);}

Ha-P Coding 🙂

Posted in C#, Collections & Generics, Delegates | Tagged: , , , | 16 Comments »