I think the way I calculated the field is by using Biot-Savart law.
Calculate magnetic field sue to a coil. The solenoid is simple copy of many coils. So just need to sum up the field from one coil.
You should be able to calculate it.
The magnetic field of a bar is the same as the field of a solenoid.