Iran says its programme is purely for civilian energy purposes but critics suspect it of developing atomic weapons.
Ahmadinejad's visit to China comes at a delicate time in Tehran's relations with its ally, after Beijing backed the sanctions.
As a permanent member of the UN Security Council, China could have exercised its veto power to block the sanctions.
But it reversed its earlier opposition and backed the sanctions on Wednesday, though it continues to call for a diplomatic approach towards Iran.
On Thursday, Ali Akbar Salehi, Iran's atomic chief, lashed out at China, saying it was "gradually losing its respectable position in the Islamic world".
Marking Iran Day at his country's pavilion at the expo in Shanghai, Ahmadinejad did not directly criticise his host on Friday, but last month he rebuked Russia - which also backed the UN sanctions - warning its leaders "to correct themselves, and not let the Iranian nation consider them among its enemies".
He also skipped Friday's summit in Uzbekistan of the Shanghai Co-operation Organisation, which was attended by presidents Hu Jintao of China and Dmitry Medvedev of Russia.
Iran is an observer in the group but Ahmadinejad chose the low-key visit to Shanghai over an appearance at the regional security summit in Tashkent.
He was not scheduled to meet Chinese leaders while in China nor visit the capital, Beijing.
Bilateral trade between China and Iran reached at least $36.5bn last year.
Iran meets 11 per cent of China's energy needs and Chinese companies have major investments in Iranian energy extraction projects and the construction of roads, bridges and power plants.