July 2, 2012

How to use soapUI to review ListData.svc

sIntroduction
SoapUI is a free tool that can be used to test out of the box ListData.svc service provided by sharepoint. This service is available at /_vti_bin/ListData.svc for any of your sharepoint site. Here is how we can try it out using SoapUI.
Step1: Install sopa UI and click on File > New SoapUI Project. Add some project name and check "Add REST Seervice:" like shown in following figure and then click OK

Step2: After clicking on OK another window will open like following, just click on OK

Step3: New REST resource window will appear. In resource name enter site url and in resource path/endpoint provide list/document library name and click on "Extract params" button. Following is the screen that shows sample data.

Step4:That will automatically create a new request called Request 1.This request will automaticlaly detect endpoint and path to your list/document library. If it is not, just click on"-no endpoint set-" and click on add new endpoint. Enter site url in the dialog again.

Step5: Maximize "Request 1" window in soapUI. In botton left corner you will see " ... ", click on it and you will be able to provide sharepoint authentication details there.

Step6: Once you are done with authentication details you can click on execute icon at top left corner of "request 1" window (marked in above figure) to execute the request and you will be able to see response at right hand side window.
Step7: ListData.svc can also return json data in response out of the box. Just try to provide accept = application/json like shown in figure below:


If you have any questions you can reach out our SharePoint Consulting team here.

SMTP Server For Development Farm – smtp4dev

Developing for SMTP can be a time consuming hell. One can work out encoding issues the hard way – with a proper SMTP server installed – or skip all that and make it easy. Enter SMTP4Dev's, which emulates an SMTP server, and allows one to see what's being sent around in much easier way.
Scenario:
I am working for the alert me functionality for the list and List Items modification and deletion but due to some configuration problem in my development environment,
I did not receive e-mail in consistent manner
After some goggling I have found one very useful project in codeplex for testing local smtp functionality without any installation.
Smtp4dev.exe does not require any installation.
  • Double click and open smtp4dev.exe
  • Click on option button and go to server tab
  • Set domain name anything you like for example: local.abc.com
  • Click Ok.
Now Open your Central Administration
  • Go to System Settings à Configure outgoing e-mail settings
  • Provide that same name of your domain name in Outbound SMTP server
  • Provide anything with domain name as from address. For example: test@ local.abc.com
  • Provide anything with domain name as Reply-To address. For example: Reply@ local.abc.com
Note: Make sure that the domain name provided in smtp4dev and the domain name in from address and to address are same.
Next,
  • Open C:\Windows\System32\Drivers\Etc
  • Open local file with administrator rights using any text reading software like notepad.
  • Enter entry like à 127.0.0.1 local.abc.com
    (Make sure, this name must be same as Domain name in smtp4dev.exe)
  • Save and close
Now whenever your share point server will send any mail, it is captured and displayed as shown in screenshots below.

This is a mail sent by share point which you can Inspect, in order to see the contents of the email sent, check the encoding, etc.:

If you want to get fancier, the proxy server allows for customizing the way it behaves:


If you have any questions you can reach out our SharePoint Consulting team here.

June 18, 2012

SharePoint Search: Partial Page Exclusion

Out of the box, SharePoint provides a mechanism for excluding publishing pages from the search index by any number of criteria, but what if you want to exclude only parts of a page? This becomes useful when you have content on numerous pages that contains common keywords.
For Example, In Our Production site we have master page and in this master page , Header , Left Navigation and footer for the Pages.
So when someone performs a search for "Careers" they will get back every page in your site, instead of just the Careers and related Careers pages. To prevent this, we needed a way to keep SharePoint from indexing that content when it's performing a crawl.
Web Control
We decided that a System.Web.UI.WebControls.Panel control would be a good model to build my control on. It allows you to easily drop it in the page layout using SharePoint Designer, and you can put other html and controls within it. I didn't want to inherit from the Panel control though, because it adds unwanted 'div' tags to the rendered output. The key to the Panel control's behavior are the following two attributes on the class:
[ParseChildren(false), PersistChildren(true)].
These attributes allow the content within the control to persist as controls and not properties of this control.
User Agent
The second part of the equation is knowing when to show or hide the contents of the web control.
SharePoint gives us a way to identify that it's performing a crawl through the UserAgent property of the http request by adding "MS Search" to it.
Code
Putting this all together we come up with the following class:

[ParseChildren(false), PersistChildren(true)]
    public class SearchCrawlExclusionControl : WebControl
    {
        private string userAgentToExclude;

        public string UserAgentToExclude
        {
            get
            {
                return (string.IsNullOrEmpty(userAgentToExclude)) ? "ms search" : userAgentToExclude;
            }
            set
            {
                userAgentToExclude = value;
            }
        }

        protected override void CreateChildControls()
        {
            string userAgent = this.Context.Request.UserAgent;

            this.Visible = (!string.IsNullOrEmpty(userAgent)) ? !userAgent.ToLower().Contains(UserAgentToExclude) : true;

            base.CreateChildControls();
        }

    } 
Using It
Register Web Control within Page.
<%@ Register Tagprefix="SearchUtil" Namespace="ABC.SharePoint.WebControls" Assembly="ABC.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxx" %>
After adding the register tag to the page layout, we can wrap all the content we want to exclude with our control:
<SearchUtil:SearchCrawlExclusionControl ID="SearchCrawlExclusionControl1" runat="server">
    <div>Some Content To Excludediv>
SearchUtil:SearchCrawlExclusionControl>
Test this:
After applying this User control to all your excluding Div and HTML tags.
Make Incremental or Full crawl of you web site.
How to edit the User Agent string in Mozilla FireFox
To change the User Agent string, just enter about:config as an address in the address bar of FireFox, the location where you normally enter a URL (link). I recommend to preserve the original value, which you can get when you enter just about: in the address bar.
Now press the right mouse button to get the context menu and select "String" from the menu entry "New". Enter the preference name "general.useragent.override", without the quotes. Next, enter the new User Agent value you want Mozilla Firefox to use.
I added my name and a link to my web site to the original value. You can also pick one from the list of User Agent strings. Check the new value by entering about: in the address bar.
How to edit the User Agent string in Google Chrome
Here's how to change the user agent:
  • open the Developer Tools (Ctrl+Shift+I on Windows/Linux, Command - Option - I on Mac OS X)
  • 2. click the "settings" icon at the bottom of the window
  • 3. check "override user agent" and select one of the options (Internet Explorer 7/8/9, Firefox 4/7 for Windows/Mac, iPhone, iPad and Nexus S running Android 2.3).

You can also select "other" and enter a custom user agent.
Note: Here to test for SharePoint search write MS Search as User Agent in Other option.
How to edit the User Agent string in Internet Explorer
To change it open your registry and find the key
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform].
Each value name listed in this key will be sent to the remote web server as an additional entry in the user agent string. To remove any additional information delete the values within the [Post Platform] key. To add additional entries create a string value and name it the string you want to be sent.
Restart Internet Explorer for the changes to take effect.
Note:Here to test for SharePoint search write MS Search as User Agent in Other option.
If you have any questions you can reach out our SharePoint Consulting team here.