Two-dimensional (2D) materials have been emerging as potential candidates for the next-generation materials in various technology fields. The performance of the devices based on these 2D materials depends on their intrinsic band structures as well as the extrinsic (doping) effects such as surrounding chemicals and environmental oxygen/moisture, which strongly determines their Fermi energy level. Herein, we report the UV treatments on the 2D transition-metal dichalcogenides, to controllably dope the samples without damaging the crystal structures or quenching the luminescence properties. More surprisingly, both n-type and p-type doping can be achieved depending on the initial status of the sample and the UV treatment conditions. The doping mechanisms were elaborated on the atomic scale with transmission electron microscopy and ab initio calculations. The facile doping by UV light has potential to be integrated with photolithography processes, aiming for the large-scale integrated device/circuits design and fabrications