The first time, the 1862 Maryland Campaign, Lee planned to capture the city after he had taken Harpers Ferry, West Virginia, but he was prevented from doing so by the Battle of Antietam and his subsequent retreat back into Virginia.
In the first instance, Lee's plan for the 1862 Maryland Campaign involved capturing the city following his capture of Harpers Ferry, West Virginia; but this was blocked by the Battle of Antietam and his subsequent return to Virginia.