To what extent does mainstream Christian doctrine teach that knowing a spirit's name gives you power over it? A while ago I was at a resort with a man who for many years worked as a church painter. He introduced me into some pieces of Christian doctrine.

He told me that the humans' souls, the angels, demons and the God himself all are the spirits.
Knowing a spirit's true name gives unlimited power over it.

For example, Jesus asked for the demon's name before he expelled it from the man and into the herd.

Consequently, nobody knows the true God's name which is the highest secret, because anybody who knew it would have God's power.

I wonder to what extent this explanation reflects mainstream Christian doctrine.
Actually, this is more Kabbalah than Christianity and has further roots in the occult and other non-Christian mysticism and folklore (Rumpelstiltskin comes to mind, which is a decidedly non-Christian story). 

The idea that knowing the name of a beast/demon/whatever gives you dominion over it came from the idea that naming a beast/demon/whatever showed your already existing domination over it. It's a very ancient idea that we see displayed in Genesis 2 when God brings all the beasts to Adam so that he can name them 1 2.

The concept is often called knowing the True Name and also has its roots from a time when it was believed that language itself, or a special unknown language, held actual power (which is where the concept of spells comes from too). These concepts are not foreign to the Bible, but because of your modern eye, you might have over looked them. As already mentioned, Adam names the beasts in Genesis, but going further we see that God doesn't necessarily create in Genesis 1 with His own hands, but by simply speaking and with authority too. We see this again with the prophets, where they would speak with the authority of God ("thus saith the Lord"). We also see this in the New Testament in Acts when the disciples cast out demons "in the Name of Jesus." We even see this in John 1 where Jesus is called the "Word" that was and is with God.

Historically, this god-like power extended to kings, where any utterance from the king was not only legal law, but divine and natural as well. 3 4 Today, this extends somewhat into Christendom. For example, within the Roman Catholic Church, there is the doctrine of Papal Infallibility, though I concede that this doctrine did not originate from this ancient mythical concept, and also in a few sects, such as LDS and Seventh Day Adventists, that believe in a modern prophet that brought or clarified the Word of God, which also has different origins. Even secularly, this idea that words hold real power persists, as evidenced by the classic metonymy "The pen is mightier than the sword."

In general, "mainstream" Christianity really avoids these kinds of things. Most people find the topic very unnerving. Out on the edges is where you will find opinions favoring this. It is very difficult to Biblically support it. This idea leaves the impression that you can have some kind of intrinsic power over any spirit. Instead, what is readily supported is that it is God's power, Jesus Christ's power, that conquers the evil spirit. Jesus casts out demons by his own authority, while the disciples in Acts cast out demons "in Jesus' name," demonstrating that they have no power of their own, but that Jesus does.

Additionally, what is very common practice for exorcising demons is to never actually address the demon except to command it from the possessed (I can't find a source for this right now). This would show that in practice, asking for its name is something you should not do anyway, even if it would tell you the truth.



Addendum

In case you might ask about the story of the demon named "legion" ...

It's not particularly clear why Jesus wanted to know the demon's name, but it is very clear that the demon was in full submission to Christ before He asked.


  When he saw Jesus from a distance, he ran and fell on his knees in front of him. He shouted at the top of his voice, “What do you want with me, Jesus, Son of the Most High God? In God’s name don’t torture me!”
  Mark 5


The demon immediately pleads and begs Jesus to spare him from a grisly fate. Jesus didn't even need to address the demon. It merely saw Him from a distance and fell promptly into submission.

Regarding having the power of God ... Any tradition that would claim that having God's power is possible, even only theoretically, is verging on blasphemy. I don't know for sure, but this does sound like something you would read in Kabbalistic literature.



Sources


Adam and the Woman by Sandra King
Genesis 2, Adam and Eve, and Authority by Matt Slick - CARM
Divine Right of Kings Definition - Duhaime's Law Dictionary
Divine right of kings - Wikipedia


An interesting related question on Literature SE: Where did the idea of a "true name" come from?