If I'm playing a piece (piano) in D harmonic minor, I only sharp the 7th (C) if there is an accidental. Is that right?
The piece is not in D harmonic minor. It is in D minor. Harmonic minor refers to a scale, not a key. Only play C#s if they are written as sharps. If not, just play C naturals.
D minor is the relative minor to F major. As such, it's given the basic key signature of that key - one flat - Bb.
Minor keys have vagaries which muddy the waters a little. There's the natural minor notes, which mirror those of F major exactly. Some pieces in Dm use those exclusively. Sometimes a more definitive leading note is needed, so the penultimate note of the natural scale is raised. Hence the C# from the question.
Sometimes, the interval between the 6th and 7th note in the harmonmic minor scale doesn't sound too good, so that's also raised. Hence the melodic minor.
However, the key signature of Dm stays as Bb only. If the piece needs C to be raised to C# each and every time, so be it. It gets an accidental each and every time.
Afew composers actually did write out key signatures with something like Bb and C#, to signify Dm, but it never really caught on. At the end of the day, it's not difficult to realise that with Bb as the key sig., and some C# accidentals, that it's going to be Dm, using harmonic notes. Just as, with the same key sig, if the piece centres around G, it's probably G Dorian.
You're looking at this backwards. Presumably you have a piece with a key signature of one flat, and a tonal centre of D. So you, probably correctly, surmise it's in D minor. It's very possible there will be a sprinkling of C# accidentals. If they occur in a scalic passage, it's very likely a D harmonic minor scale. That is One Of The Things That Often Occur In A Piece In D Minor. Nothing more and nothing less. There are many more. Some of them use notes that aren't in ANY form of the D minor scale!