while using saveNode I need to provide the correct file extension, however I failed to know the node class type to create the proper if sentence.
Example:
node is vtkMRMLScalarVolumeNode => filename ends in .nrrd
node is vtkMRMLSegmentationNode => filename ends in .seg.nrrd
node is vtkMRMLTransformNode => filename ends in .h5
Supported file extension also depends on the associated node content (for example, if master representation of a segmentation if closed surface then file extension will be .seg.vtm). You can get the list is usable file type descriptions and file extensions from the storage node:
Yes you can get the storage node from the data node like that. If you are not sure if the data node has a storage node already then call node.AddDefaultStorageNode() before (it is safe to always call it because the method simply does not do anything if the data node has a storage node already).