I created several groups using the following code:
SPWeb currentSite = SPContext.Current.Web;
currentSite.EnsureUser(groupOwner);
currentSite.SiteGroups.Add(siteTitle1, currentSite.SiteUsers[groupOwner],
currentSite.SiteUsers[groupOwner], siteDescription1);
How can I assign these groups to a specific subsite?
You should get a subsite object, like this:
var subWeb = currentSite.Webs["MySubSite"];
And then use your code:
subWeb.EnsureUser(groupOwner);
subWeb.SiteGroups.Add(siteTitle1, currentSite.SiteUsers[groupOwner],
subWeb.SiteUsers[groupOwner], siteDescription1);