How can I determine where to position a capo based on the key of the music I am playing? I current can only play songs in the key of C with no capo. Is there any rule to follow?
If you are currently playing it in the key of C and want to use the same finger shapes for D just pop the capo on your 2nd fret. This shifts everything up 2 semitones, ie. from C to D.
But as Wheat mentioned in his comment, if you learn different finger shapes, you can play in any key without using a capo. Most users of capos use them either for ease (if there is a tricky chord that just works better in a particular shape) or for a particular sound (letting open strings ring is very different to playing barre chords higher up the fretboard)
To elaborate further what Wheat and Dr. Mayhem mean about playing without the capotasto [yes, I had to look it up].
You can transpose the chords in your head, from C to D, by shifting each chord up a whole step. So when you read C, play D. When you read D, play E. When you read Am, play Bm. Etc.
Playing with all barre-chords can be a useful intermediate step. As is Nashville notation. [Actually, I really mean Roman-numeral notation. I've learned that 'Nashville' uses arabic numerals, which are often already covering the page! The point is notating chords by their function in the scale. Then you can apply the pattern to any scale.] These techniques focus attention on the internal structure of the song, rather than its external location on the Concert C scale.
Edit: Re-reading the question, I'm now a little confused. So here's some hemming and hawing to cover all the bases. :)
If the song is simply written in D, then you don't have to do anything (nor need you use a capotasto) to play it. It just means that F and C are sharp, so D major and A major are possible instead of D minor and A minor like you have in the key of C. Chord symbols should already account for this and give you the character (Major/minor) and any accidentals on the root (C♯° & F♯m are two chords from the harmonized D Major scale). Music written in staff notation should remind you of the key at the start of each line, just after the clef.
If the song is, somehow, written for an instrument in the Key of D, then you can capo at the second fret to perform the key correction. This is essentially what a B♭ horn player must do mentally to read "C" music.
In general, for music written for an instrument in the key of X (B♭, E♭, whatever), the key note X is written as C on the page. Note you can also de-tune the strings to perform a key correction in the reverse direction; a guitar de-tuned a whole step can read B♭ horn charts with ease (very useful in pep-bands and concert bands where your "closest" choice might be marimba, but the marimba part doesn't have enough info (and the bassist won't share); in these situations, the horn-parts will show you the harmony, the backing riffs, and the melody, but you have to correct the key).
To play in the key of D with the 'C shape,' you'd want to capo your guitar on the second fret. Each fret represents a half step and there are two half steps from C to D (so if you capoed on the first fret you'd be playing in C# with the 'C shape').
The reason I use the term 'C shape' is because I learned very early in my playing about the CAGED method which helped me learn all about what you are somewhat referring to. The chords C, A, G, E and D are the five basic shapes played with open strings meaning those can be moved all around the guitar. Think about a basic B chord. That chord is actually just an A chord moved up two frets (with your first finger acting where the open notes were). If you play a D up four frets then you will be playing an F# (D#-E-F-F#).
So you could play a song in the key of D with the capo on the fifth fret if you played with the open A shape. On the second fret with the open C shape. On the seventh fret with the open G shape, etc.
Google the 'CAGED method' and it will help immensely in your understanding.
Even though this is a guitar question, the easiest way to think about this is to visualise a piano keyboard.
Going up one fret on your guitar, is equivalent to going up one key on the piano - including the black keys.
So when you finger the first fret of the E string, you are playing an F. When you finger the second fret of the E string, you are playing an F#.
A capo has the same effect as a finger. So if you put a capo on the second fret, you change your "open" strings from E,B,G,D,A,E to F#,C#,A,E,B,F# -- prove it to yourself by finding the notes on the piano image and counting two semitones up.
The same principle works with chords. Since you play your chord shapes moved up the neck the same number of frets as the capo position, the whole chord is transposed. So if you play an E major shape with a capo on the 2nd fret, it's an F# major.
So, to answer your question directly: let's say you want to play a tune in G major, but you want to use C major shapes. How many frets up is G from C? Start at C on the piano keyboard, and count one-key steps until you reach G. C#,D,D#,E,F,F#,G -- 7 steps, so put your capo on the 7th fret.
The same reasoning will apply when you advance to barre chords (which you should do as soon as possible). Since you are fingering every string, barre chords are movable. If you move a barred F up 4 frets, you can see from the piano picture, that you'll be playing an A. One way to think of a capo is as a static index finger for barre chords.
Some people can be a bit snobby about capos, because it can be a cop-out alternative to learning a full complement of chord shapes. But there are worthwhile reasons to use a capo; it lets you play different chord inversions over a song in a particular key. I particularly like to to capo my 7th fret when playing alongside another guitarist who's playing chords without a capo. It prevents the two instruments competing for the same range, and my acoustic has a sweet sound in that register.
One final note -- you are asking how to play a song in D, using C shapes. The standard chord shapes for D, G, A are much easier than those for C, F, G -- so a capo might not be your best option in this case.