Well, this is a pretty simple question, and many of you out there already know how to do it. SQL Server 2005 introduced a number of system views that gives the size occupied by each data/log file in the database. So it is a matter of just querying one of those system views and read the "size" column.
We were trying to configure an alert when the file size goes above a given limit and realized that the "size" column actually stores the number of pages. Each page is 8 KB. So to get the actual size of the file in KB, you need to multiply the value in "size" column with 8.
Read the article: http://www.sqlserverandxml.com/2008/10/how-to-find-space-used-by-data-mdf-ndf.html