There may be many instances where we have to activate "SharePoint Server Publishing Infrastructure" through Code by feature activation. In this blog , I will provide the code below.
using(SPSite CurrentSite = new SPSite(SPContext.Current.Site.Id))
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentSite.Features.Add(new Guid("{f6924d36-2fa8-4f0b-b16d-06b7250180fa}"));
CurrentSite.AllowUnsafeUpdates = false;
}
f6924d36-2fa8-4f0b-b16d-06b7250180fa - Guid for the Publishing Infrastructure feature.