The lockdown announcement comes amid a new daily record for asymptomatic COVID-19 infections.
Shanghai will be divided into two parts for the lockdown and will use the Huangpu River as a guide, according to authorities.
The city of more than 26 million reported 47 new COVID-19 cases that are symptomatic and 2,631 new asymptomatic cases on Saturday.
Authorities say that the districts to the east of the Huangpu River, as well as some to the west, will be under a lockdown and will undergo testing from March 28 through April 5, while the other areas will be under a lockdown and will undergo testing from April 1 through April 5.
The restrictions have caused Brent Crude to drop $3.68 to $116.97, and U.S. crude dropped $3.30 to $110.60.
During Shanghai's shutdown, ride-hailing services and public transportation will not operate, and unapproved vehicles will not be permitted on the roads.
Factories will also be forced to suspend operations but companies that are involved in public services or the supply of food can operate during the lock-down.
"The public is asked to support, understand and cooperate with the city's epidemic prevention and control work, and participate in nucleic acid testing in an orderly manner," the government said in a WeChat post.
Reuters contributed to this report