using Microsoft.Office.Server;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.Search.Administration;
static void CreateScope()
{
SearchContext searchContext;
using (SPSite site = new SPSite("Your SiteCollection Site"))
{
searchContext = SearchContext.GetContext(site);
Scopes scopes = new Scopes(searchContext);
Scope newScope = scopes.AllScopes.Create("CustomScope", "Scope Description", new Uri(site.Url), true, "Your Custom Serach aspx Page", ScopeCompilationType.AlwaysCompile);
newScope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include, UrlScopeRuleType.Folder, "Folder Name");
newScope.Update();
ScopeDisplayGroup group = scopes.GetDisplayGroup(new Uri(site.Url), "Search Dropdown");
group.Add(newScope);
group.Update();
}
}