Here is the code
SearchContext searchContext = SearchContext.GetContext(
Scopes scopes = new Scopes(searchContext);
Scope newScope =
scopes.AllScopes.Create(
"This is a sample scope for testing purpose", null, true,
"Resultpage.aspx", ScopeCompilationType.
Schema sspSchema = new Schema(searchContext);
newScope.Rules.
sspSchema.
"urn:content-class:SPSPeople")
scopes.StartCompilation();
You can deploy it via feature. Here is the complete code.
public override void
FeatureActivated(
FeatureActivated(
{
ServerContext context = ServerContext.Current;
if (context != null)
{
SearchContext searchContext = SearchContext.GetContext(
Scopes scopes = new Scopes(searchContext);
Scope newScope =
scopes.AllScopes.Create(
GetConfigValue("Description"), null, true,
GetConfigValue("ResultPage"), ScopeCompilationType.
Schema sspSchema = new Schema(searchContext);
newScope.Rules.
sspSchema.
"urn:content-class:SPSPeople")
scopes.StartCompilation();
}
}
public override void
FeatureDeactivating(
{
ServerContext context = ServerContext.Current;
if (context != null)
{
SearchContext searchContext = SearchContext.GetContext(
Scopes scopes = new Scopes(searchContext);
Scope newScope = null;
try
{
newScope = scopes.GetScope(null,
"MycustomScope"
}
catch (Exception ex)//For Scope Not Found Exception
{ }
if (newScope != null)
{
scopes.GetScope(null,"MycustomScoe").Delete();
scopes.Update();
}
}
}
public override void
FeatureInstalled(
{
//throw new NotImplementedException();
}
public override void
FeatureUninstalling(
{
//throw new NotImplementedException();
}
Follow this link. I achieved with this
ReplyDeletehttp://vamshikrishnabudarapu.wordpress.com/2013/12/16/creating-search-scopes-programatically-using-spnavigation-class/