Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm getting error when i try to add a crawled property to managed property "contentshidden"

Anyone know why the problem can ben, when i add a mapping to empty mapping property it is ok, but when i add to contentshidden then i get an error:

 IList<CrawledProperty> crawledProperties = new List<CrawledProperty>();
            Schema schema = new Schema(searchServiceApplication);
            ManagedPropertyCollection allManagedPropertiesCollection = schema.AllManagedProperties;

            foreach (Property p in propertiesList)
            {
                foreach (CrawledProperty crawledProperty in schema.QueryCrawledProperties(string.Empty, 1000, Guid.NewGuid(), string.Empty, true))
                {
                    if (crawledProperty.Name.Contains(p.Name) && !allManagedPropertiesCollection.Contains(p.Name))
                    {
                        string name = crawledProperty.Name;
                        if (!crawledProperty.Name.Contains("ows"))
                        {
                            crawledProperties.Add(crawledProperty);
                            ManagedProperty managedProperty = allManagedPropertiesCollection.Create(p.Name, ManagedDataType.Text);
                            ManagedProperty hiddenContentManagedProperty = allManagedPropertiesCollection["ContentsHidden"];

                            Mapping mapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, managedProperty.PID);

                            MappingCollection mappingCollection = managedProperty.GetMappings();
                            MappingCollection hiddenContentsMappingCollection = hiddenContentManagedProperty.GetMappings();
                            if (!mappingCollection.Contains(mapping))
                            {
                                mappingCollection.Add(mapping);
                                managedProperty.SetMappings(mappingCollection);
                                managedProperty.Update();
                            }
                            if (!hiddenContentsMappingCollection.Contains(mapping))
                            {
                                hiddenContentsMappingCollection.Add(mapping);

                                hiddenContentManagedProperty.SetMappings(hiddenContentsMappingCollection);
                                hiddenContentManagedProperty.Update();
                            }
                        }
                    }
                }
            }

UPDATE: The error that im getting: "The mapping must be to the managed property being set."

Thanks in advance

share|improve this question
    
You get an exception? Post the exception :-) –  Dennis G Jan 10 '12 at 12:33
add comment

1 Answer 1

I suspect this line is the root cause:

hiddenContentsMappingCollection.Add(mapping);

You are trying to add a mapping created for one managed property to another managed property. mapping was created for managedProperty and not hiddenContentManagedProperty (see the last parameter):

Mapping mapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, managedProperty.PID);

The solution would be to create a second mapping like this:

Mapping hiddenContentsMapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, hiddenContentManagedProperty.PID);

Then you would add this mapping to the hiddenContentsMappingCollection:

hiddenContentsMappingCollection.Add(hiddenContentsMapping );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.