October 22, 2012

SPLongOperation

Use Case:
SPLongOperation class Sets the Web page image to the image used by the server to indicate a lengthy operation (typically, an animated image with associated text).
So, when you are starting a workflow, or doing some server side processing that can take long period than asp.net request execution timeout period, you can use this class to do such operations.
Usage:
   1:  SPLongOperation.BeginOperation beginOperation = null;
   2:                  if (beginOperation == null)
   3:                  {
   4:                      beginOperation = delegate(SPLongOperation longOperation)
   5:                      {
   6:                          // Long running code here ...
   7:                          longOperation.End(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current, "");
   8:                      };
   9:                  }
  10:                  SPLongOperation.Begin(beginOperation);
 
 
Notes:
You need to import System.Threading. At the end of your operation, generally you do longOperation.End() and page will be redirected to the specified url. If you are doing it in sharepoint dialog, it will automatically close dialog and redirect parent page.

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

Printing InfoPath Forms

Print option is normally not available as an option on Ribbon in InfoPath templates. So if one wants an option to “Print” InfoPath form then they can use the following steps below. Before starting off the InfoPath should be published as a Content type and a Page with InfoPath form Web Part must be created.
  • Open the Display Form web part page (make sure to select the correct content types if you have more than one....). You can do this by clicking Form Web Parts > (Content Type if you have several) Display Form
  • Edit the InfoPath Form Web Part. Set the Chrome to include just the Title.
  • Add a Content Editor Web part to the page. Set it to Hidden.
  • Add the JS from below link in the HTML source of the Content Editor Web part.
    https://www.nothingbutsharepoint.com/sites/eusp/Pages/jquery-for-everyone-print-any-web-part.aspx
  • Save the page.
You can now click the little icon (or you can modify the JS to insert a button to say 'Print Form') and the Print Preview of the Info Path web part gets opened, along with popup for setting printer options.
In the above JS script, the function “printWebPart” can be modified and replaced by the below script function

  printWebPart(tagid)
        {
            if (tagid)
                {
                    this.print();
                }
        }
 

This will directly open up the popup for setting printer options without showing the Print Preview.

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

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.