Since then, Duanfang took the post of Shaanxi provincial judge, administrative commissioner, and agent of the Shaanxi governor. In 1900, after Beijing was occupied by the forces of the Eight-Nation Alliance after the Battle of Beijing, Empress Dowager Cixi and the Guangxu Emperor fled to Shaanxi. Duanfang was transferred to a new post as Henan provincial administrative commissioner, and then to governor of Hubei. In 1902, Duanfang served as acting Viceroy of Liangjiang, Afterward, he was transferred to a new post as Governor of Hunan. In his successive posts, he encouraged students to study abroad, known as an englightened person, "enthusiastic in experience in foreign and domestic affairs."