When working with SMO and Indexes there are times that you want to get the fragmentation of this particular index. In SMO there is a method on the Index called EnumFragmentation. When you call this method, there is a bug in SMO out on Connect (SMO Index Enum Fragmentation…) that you should vote for. This is a very impactful bug as this is the only way in SMO to get the Fragmenation information on an Index.
The bug is this. When you call EnumFragmentation() you get the entire Database fragmentation by index instead of for the Index that you are calling it from. Normally what you would expect is to see
select * from sys.dm_db_index_physical_stats(9, 39399393, NULL, NULL, 'SAMPLED')
Instead you see
select * from sys.dm_db_index_physical_stats(NULL, NULL, NULL, NULL, 'LIMITED')
This is crazy as you only get a limited set, which I know you can change with the method above by specifying the type of Detail (‘DETAILED’, ‘SAMPLED’, ‘LIMITED’) but it defaults to LIMITED.
Vote up the bug if this is something that affects you and your work.