Since a solenoid is an electromagnet, it produces EMF which can damage any electronic devices driving it. You must use a silicon diode D1 (1N4001 recommended) to absorb the EMF, connected in reverse bias. (in reverse).
Operating voltages range from 6 to 24 volts. Generally the higher the voltage, the more powerful the solenoid is.