Sharepoint 2010 search: How to modify search query before submit (programmatically?) - search

I'm making a custom search box Web Part, similar to the OOTB Web Part from SharePoint
(SearchBoxEx class).
I'm interested in modifying the search query with additional text before it is submitted, based on a custom checkbox added on the Web Part.
Any help on how I can achieve this?
UPDATE:
I've used the AppendToQuery and AppQueryTerms properties, but this will rewrite the text in the search box as well. I'm interested in passing the values "in the background", maybe as an extra parameter. Point is that the query modification should happen without the user seeing it explicitly.

In the core result webpart there is a property where you can append text to the query and you will not see that in the textbox.
Best,
Bibhu

I when I had to customize People Search, I opted to roll my own web part and just called Response.Transfer to the Results.aspx and appended query string parameters to the URL. This wasn't the most elegant solution, but it was a quick way to modify the query "behind the scenes."
I'm sure you could develop an application page and set it as the Search Box web part's Results page. Put your custom logic in the page_load and then transfer (or do a form POST) to the actual results.aspx page.
I'm now developing an Extension of SearchBoxEx myself, and I'm currently trying to figure out how to call the base method that submits the query too. This blog shows how to call the internal CreateAdvanceSearchLink method of the SearchBoxEx class: http://pholpar.wordpress.com/category/search/

Related

Use SPFx to modify the 'edit form' from a modern document library

Right now I am learning SPFx for SharePoint Online. My customer wants to modify the 'edit form' of a document library in a way that if a user starts typing keywords into the Summary field, predifined keywords are displayed which share the same letters in the beginning.
I was wondering if I can use SPFx to geht this job done
I thought maybe I can bind the ID of the summary textbox to a javascript file which then does the heavy lifting.
Thank you for your help
Yes, you can create a edit form with SPFx, however, you can't replace the default edit form with the one you created with SPFx.
The only way to replace the default edit form is using PowerApps or InfoPath to create a new form, however, I don't think that we can achieve the goal with these two solution.
Maybe you should create your own list web part, and implement the edit button of the web part, such that the web part will show your edit form with the auto completion.

SharePoint 2010 - Search Box Web Part and Search Results Page Customization

Would someone be willing to offer me some assistance with customizing the search results page and the search box web part properties.
First problem: Search Box Properties
When I add an additional query term (eg. fileextension="xml") the search runs as expected but the refinement panel dissapears on the search results page. I don't want it to dissapear! I just want certain filters to be pre-applied.
Second Problem: Search Results Page
How do I customize the way results are displayed. For instance, I would like to add different refinement options to the refinement panel. I would also like to change what information is displayed under each individual result. Currently it seems to show a summary of the content, followed by the author and sometimes the date. I'd like to change this. How???
Any help greatly appreciated.
The results part you need to update the XSLT, You can do this via one of the web part properties. You will also need to make sure that the fields you want to put in to the results are included in your columns(Also a web part property)
Check this out
https://littletalk.wordpress.com/2011/08/26/customizing-search-core-result-xslt-in-sharepoint-2010/
Refinement options are based on Your crawled properties. Check this out
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/03/15/get-to-know-the-refinement-web-part-in-sharepoint-2010-enterprise-search.aspx
Not sure as to why your refinement panel is disappearing, Check to see if the URL changes dramatically when you add your fileextension="xml" to the web part property, it may be that this addition is changing the URL so much the refinement panel is loaded or can't load but don't hold me to this
cheers to the
Truez

XSLT Web Part to display HTML

Please excuse if there is a better way to do this, I'm not too familiar with SharePoint web parts, I'm only just now getting into creating them.
What I want to do is have a web part that I can drop into a page, give it a parameter, and then the web part does it's API calls with said parameter, does some XSL transformation, and spits out the HTML that I want to display on the page. In my mind it seems like a simple little web part to write, I just want to make sure this is the best way to go about it and not be duplicating something that could already be existing.
I've gone through this creating a basic web part walkthrough, and I figure I can use the web part property to get the parameter from the user. How would I get it to output HTML though? I changed the "Hello, world!" text to output some HTML and it seemed to have gotten stripped out?
Thanks a ton, and sorry if anything seems noob-ish!
From what I see, there are two main parts to what you want to do.
Get your parameter into your query
Format the results with some HTML
Reuse it later
There are a lot of ways to do this, but I'm going to outline what I believe to be the fastest and most simple.
Getting your parameter into your query
In SharePoint 2010, SharePoint designer has some great options for this.
So step 1 is to open the webpage in SharePoint Designer.
Click the Insert tab and click the Data View dropdown and select the list you want to get data from.
Now click on the Options tab and click on Parameters
The dialog shows you some of the options for pulling info into your query.
A query string parameter is easy to use. And the server variables are also really handy.
For our example, we'll pick query string and set the default value to 1 (which will be the ID of an item we want to be retrieved). Since we've set this as the default, even if the query string is blank we'll still get our default in our parameter.
Then click on Filter.
We set our Field Criteria to use the parameter we just made.
Now you can save the page in SharePoint Designer and test your results. Pretty fast.
Format the results with some HTML
In SharePoint, XSLT is the best way to put your own HTML around some data you've retrieved from SharePoint.
Also, for getting a parameter into your query, we can add that with a parameter binding:
If you're new to XSL, here's the best xsl tool:
http://spexp-blog-files.s3.amazonaws.com/blog/files/spe-magic-data-view-builder.xsl
To use the magic dataview builder, save this file to documetn library in your farm.
If you’d like to centralize your XSL template for greater reuse (highly recommended), you can put the individual XSL files into a central location for storage. In a WSS or SharePoint Foundation environment, I’d recommend using a Document Library in the root site of your Site Collection. In a MOSS or SharePoint Server 2010 environment, I’d recommend placing the XSL files in the /Style Library/XSL Style Sheets location, as this is where SharePoint stores its XSL by default.
Then paste the url to the file into the XSL Link to replace main.xsl and change Default to FALSE. This property is located near the end of the <XmlDefinition> tag as you view the webpart in Designer.
... <XslLink Default="TRUE">main.xsl</XslLink><Toolbar Type="Standard"/></View></XmlDefinition>
From there, you can save the page and the XSL wizard from magic data view builder will walk you through creating your own xsl to output your html.
Reusing Your Webpart
To reuse it, click save "To Site Gallery" while your cursor is on the wepart in SharePoint Designer. This will save the webpart into the gallery under the "Custom" group. From there, you an insert your webpart into other pages just like the out of the box webparts.
I think we need more information about what you are trying to get the web part to do. If you use a SharePoint Data View web part, you can point it at a data source, write some XSL to transform the data to render the way you want it will output the HTML to the page. For example, let's say I have a SharePoint list of training classes. I could create a data view web part that takes a query string or other input parameter as its filter, and filter the list of classes to show me just the one that matches the ID of my query string or input param. Then I could format my XSL to output details about the class rendered in whatever fancy HTML I want.
Does that help?
"I changed the "Hello, world!" text to output some HTML and it seemed
to have gotten stripped out?"
Please be aware that in your sample, it uses a LiteralControl() which by default HTML Escapes any text. So if you need HTML outputed via the LiteralControl.Text element, you will need to set the Mode to "Passthrough".
protected override void CreateChildControls()
{
base.CreateChildControls();
LiteralControl message = new LiteralControl();
// !! add this !!
message.Mode = LiteralMode.PassThrough;
message.Text = DisplayMessage; // <-- containing HTML
Controls.Add(message);
}

Sharepoint MOSS 2007 advanced search customization

In my sharepoint site, the master page template is chagned and we moved the search box into the site which showed as a web part, When the user enters a search string in that box, it should search whatever the materials available in the site itself, document library, blogs in the web, forums and wikis. Therefore, I think I need a way to figure out how these types of searches are done using sharepoint as well as how programmatically provide a search string to advanced search and receive search results. Any Idea how to do this? my code behinds are in C#
I don't think that should be any issue as sharepoint search is based upon the query string K parameter stands for Keyword, s parameter stands for scope, cs stands for contextual scope So use these parameters in query string to your results page having the core results webpart.
eg.
http:// <>/ <>/ results.aspx?k="Test Keyowrd"&s="All Sites"

SharePoint SPContext.List in a custom application page

I have a custom SharePoint application page deployed to the _layouts folder. It's a custom "new form" for a custom content type. During my interactions with this page, I will need to add an item to my list. When the page first loads, I can use SPContext.Current.List to see the current list I'm working with. But after I fill in my form and the form posts back onto itself and IsPostBack is true, then SPContext.Current.List is null so I can't find the list that I need to add my stuff into.
Is this expected?
How should I retain some info about my context list across the postback? Should I just populate some asp:hidden control with my list's guid and then just pull it back from that on the postback? That seems safe, I guess.
FWIW, this is the MOSS 2007 Standard version.
Generally speaking I try and copy whatever approach the product group has taken when looking to add functionality of my own. In this case they add their own edit/view/add pages via the list definition itself.
I built a solution that also needed its own custom "New" form, not open source unfortunately, though if you are interested you can download it, its called "Tagged Links" (Social Bookmarking for SharePoint) and you can find some links on my blog.
To give you a few hints and tips, the following should set you off in the right direction:
Created a new list definition.
Created a new Content Type In the content type you can define your own "FormTemplates" that references a Rendering Template which determine what gets displayed in the "Middle" bit of those forms.
Copied the standard Rendering Template, but then made the changes to it that I
needed.
Wrapped it all up in a solution, and deployed.
My Rendering Template actually included an overridden "Save" Button where I did a lot of the extra work I needed to do during the save.
Anyway, it is a little too much work in my opinion but, I think, it most closely matches the standard approach taken by the product developers. Let me know if you need more detail and I will see if I can put together a step-by-step blog post, but hopefully this gets you off on the right direction.
I would be surprised if you could do something in a _Layouts file that you can't do in a forms template. You have pretty much the same technologies at your disposal.
Looking at the way SharePoint works with ListItems and Layouts pages (for example "Manage Permissions" on a list item), I can see that they pass some variables in via querystrings:
?obj={76113B3A-FABA-4389-BC85-4BB2CC5AB423},6,LISTITEM&List={76113B3A-FABA-4389-BC85-4BB2CC5AB423}
Perhaps they grab the context back each time programmatically using these values.
I'm not using a custom "new form", so this might not apply. I added an event receiver to my custom content type and then do my custom code in the ItemAdded or ItemAdding events. This code fires when the event is added to a list. You can use the event receiver properties to get to the parent List, Web, and Site.
I'd like to think my issue is "special" here, since I am using a custom form. I chose to use a custom form rather than a custom FormTemplate simply because I'm doing a lot of stuff that's not very SharePoint list-like (making ajax calls to get info from a third-party app then generating some dynamic form elements based on that ajax result, then subsequent processing of that data on postback). I thought it'd be a nightmare to try this within the usual custom rendering template mechanism.
I also don't think I can supply the custom form declarations in the list definition itself, because I have multiple content types associated with this list, and each content type has its own custom form (the other type is thankfully much simpler).
Actually, my simple way of keeping the list guid in my hidden field was a very low impact way to address this specific problem. My main concern is that I'm not sure why the SPContext just loses all its usefulness when I postback here, which makes me think I'm doing something wrong.

Resources