Wednesday, June 29, 2011

SharePoint 2010 Search: Filter by Enterprise Keywords/Managed Metadata

I was looking at ways to filter SharePoint Search by the Enterprise Keywords that users are entering. On the search results page, you have the refinements right there on the left hand side, and if you inspect the url you see:

/Search/Pages/Results.aspx?k=test&r=owstaxIdMetadataAllTagsInfo%3D%2306a328dfa-d7c8-4ae1-bc35-e33936dc6807%3A"MyTag"

That's mildly helpful, but I can't tell users that they have to look up a GUID if they want a link that filters by a tag.

So what I wound up doing is creating a new Metadata Property in the Search Service Application, and then mapping it to the Crawled Property: ows_TaxKeyword

Now, when users want to do a search filter by a tag, they can just enter the following:

/Search/Pages/Results.aspx?k=MyNewMetadataProperty:'MyTag'

Friday, June 3, 2011

"Trying to use an SPWeb object that has been closed or disposed and is no longer valid."

I was getting the following error when my code was adding a web part to a SharePoint page:

Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

After reading this article:

http://insidesharepoint.blogspot.com/2007/07/trying-to-use-closeddisposed-webpart.html

I inspected my code and went from using this using (sorry had to write it like that):

using (SPSite spSite = SPContext.Current.Site)

and realized that I might be disposing the very site object that I'd need later on. So I changed it to this:

using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))

and it now works nicely!