Abu Dawud
Purification (Kitab Al-Taharah)
Book Number: 001 / Hadith Number: 4
Narated By Anas b. Malik : When the Apostle of Allah (pbuh) entered the toilet, he used to say (before entering) : "O Allah, I seek refuge in thee."
This is according to the version of Hammad. 'Abd al-Warith has another version : "I seek refuge in Allah form male and female devils."
Explaining the variance of the version Abu Dawud says : Shu'bah on the authority of 'Abd al-'Aziz narrated: "O Allah, I seek refuge in Thee," and sometimes he reported: "I take refuge in Allah." Wuhaib (b. Khalid) (on the authority of 'Abd al-'Aziz) narrated: One should take refuge in Allah.