WEbmatrix–helpers–Bing

WebMatrix Beta 2 was released on Oct 06 2010. Many changes to how WebMatrix used to work in some areas from Beta 1 to Beta 2.

Some changes went into to WebMatrix Helpers also. There are  4 new helpers that have been added to Helper family. They are :

- Antiforgery

- Bing

- Json

- Themes

In this post i am going to talk about “Bing” Helper. Because i was interested to known what this helper can do.

Bing as we all know is “Bing Is Not Google”. This is a search engine from Microsoft. Although it is getting itself positioned as not just an search engine but a decision making tool. So WbeMatrix Bing helper is to allow you to embed the Bing search box within your website.

Let me dive into the API. Bing helper can be found in the following assembly:

Microsoft.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Lets see the Bing helper methods available.

1. SearchBox

This method helps us to embed a simple search box on to the web page. The syntax is as follows:

IHtmlString SearchBox([Optional, DefaultParameterValue(null)] string siteUrl,

[Optional, DefaultParameterValue(0x142)] int boxWidth);

It takes in the following parameters:

- siteUrl – optional parameter. If provided will search the query only in that site.
                Default value is null

- boxWidth – optional parameter. Specifies the width of the search box on the 
                     page. It also has a default value so even if we don’t specify, the 
                     width comes with pre defined value of 322.

Following is the code in a razor webpage to get the Bing search box:

   1:  <div>
   2:     <p>Simple Search Box</p>
   3:     @Bing.SearchBox("http://weblogs.asp.net/kashyapa") 
   4:  </div>

As you can see i have passed the site url as “http://weblogs.asp.net/kashyapa”. So that means if i search for anything, it will search in that site only. I have not specified any width so its going to take the default value of 322.

Here is the out out of the above code:

image

The search box is neatly laid out even with the Bing search glass icon and look at the radio buttons below the search box. They even provide the option to search within the site specified or the whole web. Cool i say. So when i give a search query and hit the search, following is the search results displayed:

image

You can see that the searches are all done within the site specified while creating the search box.

2. AdvancedSearchBox

This method helps us to embed a advanced search box on to the web page. The syntax is as follows:

   1:  IHtmlString AdvancedSearchBox(
   2:  [Optional, DefaultParameterValue(null)] string siteUrl, 
   3:  [Optional, DefaultParameterValue(null)] string siteName, 
   4:  [Optional, DefaultParameterValue(0x142)] int boxWidth, 
   5:  [Optional, DefaultParameterValue(600)] int resultWidth, 
   6:  [Optional, DefaultParameterValue(400)] int resultHeight, 
   7:  [Optional, DefaultParameterValue("Blue")] string themeColor, 
   8:  [Optional, DefaultParameterValue("en-US")] string locale
   9:  )

So the advanced features of this method is that, i can specify more things than the SearchBox method. As you can see we have the following parameter options:

- siteUrl – optional, if provided the search will be done on this site

- siteName – optional, if provided will be used as caption for the search

- boxWidth – optional, if provided will be used to size the search box. default 
                      value is 322

- resultWidth – optional, if provided will be used to set the size of the result

- resultHeight – optional, if provided will be used to set the height of the result

-themeColor – optional, if provided will be used as a theme color for bing

-locale – optional, if provided the search will be localised to this locale

Here is the syntax for the same:

   1:  <div>
   2:              <p>Advanced Search Box</p>

3: @Bing.AdvancedSearchBox(
siteUrl:"http://weblogs.asp.net/kashyapa",

   4:               siteName:"Kashyapas .NET Rumbles",
   5:               boxWidth:400,resultWidth:400,resultHeight:400)
   6:  </div>

This method allows you to control the appearance of the search results too. With SearchBox the search results will be opened in a new window,

image

This is a very good helper if you plan to provide a search capability built into your site. If you are on WebMatrix and Razor band wagon. Give it a try.

Till next time, Happy Coding and Code with Passion

Technorati Tags:
  
del.icio.us Tags:

14 Comments

  • Nice example. The WebMatrix Helpers are very handy tool that help you add great features with practically only one line of code.

  • @hajan

    Thanks for the comments. Appreciate this.

    regards
    Lohith

  • Thanks! How could one search using passed parameters (using SQL Server, e.g.)
    for example:
    ColName ColumnEntry
    DateOfBirth: dd MM YYYY
    DateOfDeath: dd MM YYYY
    Artists: (NULL)
    FamousDates:

    Have Bing search "Artists" living between DateOfBirth and DateOfDeath and insert info into SQL Server ...
    or Search "FamousDates" , or whatever, and insert them or display them onto MVC or aspx page?

    Thanks again,

    Paolo

  • My programmer is trying to persuade me to move to .
    net from PHP. I have always disliked the idea because of the expenses.
    But he's tryiong none the less. I've been using WordPress on a
    variety of websites for about a year and am concerned about switching to
    another platform. I have heard very good things about blogengine.
    net. Is there a way I can transfer all my wordpress posts into it?
    Any help would be greatly appreciated!

  • I don't even know how I ended up here, but I thought this post was great. I do not know who you are but definitely you're going to a famous blogger
    if you are not already ;) Cheers!

  • Hello, i think that i saw you visited my website thus i came to “return the favor”.
    I am attempting to find things to enhance my site!
    I suppose its ok to use a few of your ideas!!

  • Very good article. I will be going through many of these issues as well.
    .

  • Fine way of explaining, and nice piece of writing to obtain facts regarding my presentation subject
    matter, which i am going to convey in institution of higher education.

  • Highly descriptive post, I liked that bit. Will there be a
    part 2?

  • Fantastic goods from you, man. I've understand your stuff previous to and you're just extremely wonderful.
    I actually like what you've acquired here, certainly like what you're stating and the way in which
    you say it. You make it enjoyable and you still care for to keep it smart.

    I can't wait to read far more from you. This is actually a wonderful website.

  • Link exchange is nothing else but it is only placing the
    other person's website link on your page at appropriate place and other person will also do same in favor of you.

  • Whats up are using Wordpress for your site platform? I'm new to the blog world but I'm trying to get started and set
    up my own. Do you need any html coding expertise to make your own
    blog? Any help would be greatly appreciated!

  • I am curious to find out what blog system you
    happen to be utilizing? I'm having some small security issues with my latest blog and I would like to find something more safeguarded. Do you have any solutions?

  • 这种眼镜品牌博士伦成立于1937年,他们推出了第一双防强光眼镜世界的飞行员。提供技术先进的镜片,以保护眼睛不受阳光,Ray-Ban的安全与风格相结合,在其范围开拓创新的眼镜。他们的小型收集灵感从成人的线,在其使用大胆的色彩和经典的设计。

Comments have been disabled for this content.