It depends on the characteristics of your "sensor/switch" and the solenoid.
If you already have the sensor/switch, can you describe it, or give a part number, or ideally a link to a data sheet?
Can you explain what you want to do, in more detail? So far, it sounds to me like you want to remotely...