Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:56:54+00:00 2026-05-30T12:56:54+00:00

I am working on Advanced Search customization. Advanced Search page has a property picker

  • 0

enter image description here

I am working on Advanced Search customization. Advanced Search page has a property picker that can be populated with managed properties and I can expose managed properties with SharePoint interfaces. However, I need to create managed property for Advanced Search Page using C#. How can I programmatically create managed properties and add them into the Advanced Search Properties? Do you have any idea about that?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:56:56+00:00Added an answer on May 30, 2026 at 12:56 pm

    I solved my problem, Firstly, I created managed property with its mapping. You can access the solution from this link.

            public void CreateManagedProperty()
        {
            // Get the default service context
            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);// Get the search service application proxy
            var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
    
            // Get the search service application info object so we can find the Id of our Search Service App
            if (searchProxy != null)
            {
                SearchServiceApplicationInfo ssai = searchProxy.GetSearchServiceApplicationInfo();
    
                // Get the application itself
                var application = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId);
    
                // Get the schema of our Search Service Application
                var schema = new Schema(application);
    
                // Get all the managed properties
                ManagedPropertyCollection properties = schema.AllManagedProperties;
    
                // Add a new property
                ManagedProperty myProperty = properties.Create(Constants.ManagedPropertyName, ManagedDataType.Text);
                myProperty.EnabledForScoping = true;
    
                // Get the current mappings
                MappingCollection mappings = myProperty.GetMappings();
    
                // Add a new mapping to a previously crawled field
                var myMapping = new Mapping(
                    new Guid(Constants.CrawledPropertyGuid), Constants.CrawledPropertyName, 31, myProperty.PID);
    
                // Add the mapping
                mappings.Add(myMapping);
    
                // Update the collection of mappings
                myProperty.SetMappings(mappings);
    
                // Write the changes back
                myProperty.Update();
            }
        }
    

    And then managed property was added to Advanced search Property;

            public void AddAdvancedSearchProperty()
        {
            string sourcefile =
                string.Format(
                    "{0}\\{1}", SPUtility.GetGenericSetupPath("TEMPLATE\\ADMIN\\ManagedProperties"), "NewAdvancedSearchProperty.xml");
            // Load the xml file into XmlDocument object.
            var xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(sourcefile);
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
    
            // Now create StringWriter object to get data from xml document.
            var sw = new StringWriter();
            var xw = new XmlTextWriter(sw);
            xmlDoc.WriteTo(xw);
            string newXmlString = sw.ToString();
    
            using (var sc = new SPSite("YOUR SITE"))
            {
                using (SPWeb web = sc.OpenWeb("searchcentre"))
                {
                    SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("pages/advanced.aspx", PersonalizationScope.Shared);
                    foreach (var wp in mgr.WebParts)
                    {
                        if (wp is AdvancedSearchBox)
                        {
                            var asb = wp as AdvancedSearchBox;
                            asb.Properties = newXmlString;
                            mgr.SaveChanges(asb);
                        }
                    }
    
                    mgr.Web.Dispose();
                }
            }
        }
    

    Note: Don’t Forget!! Start Full crawl after creating new managed property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an 'advanced search' page on a site where you would enter
I want to offer the user an Advanced Search page that toggles on or
Working on a website that has Employee and Branch entities, using a database table
In one particular Railcasts episode Ryan talks about advanced search and in that he
So recently I have been working on phonebook project that uses Binary Search Tree.
I've made an global css that I used in two page (basic search and
I'm working on a sharepoint project. After I adding the search web part. The
We are going to provide an advanced search option on a system that will
I am working on a search web page for my site. The requirements state
I was working on my advanced calculus homework today and we're doing some iteration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.