Wednesday, August 27, 2014

SharePoint 2010: Content Organizer for a Document Library

SharePoint 2010 delivers a comprehensive set of document management features. In this article, we continue our series dedicated to uncovering those features with a look at how the Content Organizer works.

Challenge:

We use SharePoint document libraries in our portal to manage all of our electronic documents.  The document libraries sometimes contain folders in a logical hierarchy structure to help us organize the documents.  In SharePoint 2010, the upload process is better in the sense that you can choose a folder to upload to, but many of our users don't really know to which folder a document should be uploaded.

Is there a way to automatically upload and store the electronic documents based on some criteria such as the contents of a metadata field?

Solution:

With the Content Organizer, a new feature of SharePoint 2010, you can create rules that will automatically move an uploaded document to the appropriate/designated location based on content type and site columns.   Follow these steps:

Step 1 – Activate the Content Organizer Feature

First, you need to activate this feature, and note that since this is a Site Scope feature, it is found under Site Actions > Site Settings menu on the Ribbon.

Click on Activate to make this feature available for your site:

Step 2 – Content Organizer Settings

Once you have activated the Content Organizer feature for a site, you will find two new menu options under Site Settings: Content Organizer Settings and Content Organizer Rules.

The other thing that happens after the activation is that SharePoint will create a document library namedDropOffLibrary along with a RoutingRules list.  The Drop Off Library will be the default destination when a user tries to upload a document to this site.  The Routing Rules list, as its name implies, contains the rules for how a document is to be routed to its final destination.

Next, configure your settings:

·  Redirect Users to the Drop Off Library: Set this check box to force all uploads to go to the Drop Off Document Library.   When an individual document is uploaded, the document properties window for Drop Off Library is displayed, at which point metadata properties can be filled in and the submission process completed. After submission, the routing rules are applied to route the document appropriately and the user is shown the final URL for the item.

·  Sending to Another Site:  Set this property to allow rules to be created that direct uploads in the current site to be sent to another site in your SharePoint Web app.   The destination site must also have the Content Organizer feature installed and activated. You can only route documents within a SharePoint Web application.

·  Folder Partitioning: This features allow you to create a threshold limit on how many documents can be stored in a document library.  SharePoint 2010 recommends a maximum of 5,000 documents per folder. Once the limit is reached, you can instruct SharePoint to automatically create a new folder, route documents to that new folder, and let the user know about the URLs of the final destination.

·  Duplicate Submissions: Use this option to let SharePoint decide what to do when you upload an item that already exists in the library.  You have the option to create a new version (if versioning is enabled in the document library), or to append unique characters to the end of the new file.

·  Preserving Context: Set this check box to send the audit logs and properties of the documents along with the documents when you route the item to another site.

·  Rule Managers: Add the users or groups that you want to be able to manage rules used by the Content Organizer. These users must also have Manage Web Site permission in order to edit rules.

Step 3 – Content Organizer Rules

Next, click on the Content Organizer Rules link to go to the popup form where you specify the rules.

·  Rule Name: Set a name.

·  Rule Status and Priority: Enable the rule and choose a priority for the rule, from 1 (highest priority) to 9 (lowest priority).  This is useful when you have more than one rule and want to be able to select which one should be applied first to the uploaded documents.

 

·  Submission's Content Type: Select a Content Type to apply the rules.  The drop down list box only shows the content types that are based on the Document content type.  The alias check box allows you to define the same content types that were renamed in other sites.  When the document is uploaded and its content type matches the names, the rule will apply to them as well.

 

·  Conditions: the Conditions setting is where the real power of this feature lies.  You can create up to six conditions where the properties of the items must meet certain values.  In this example, we will set a condition where a document begins with the prefix “SA12” in its title.

·  Target Location: Select a destination folder (it could be on the same site or a different document library in a different site) to route the document to when it has met all the criteria you set above. Note that you must enable cross-site routing (see settings in the section above) in order to see the site routing options in this form.  You can also set the folder naming convention if you choose to create a new folder.

Step 4 – Upload

Let’s try it out.  Go to any document library on your site and use the Add new document link. 

Select a document to upload.  Once the document has been uploaded, you will see the properties form below. Note the title of the form where it says “Drop Off Library”?  Remember that when you add a Content Organizer rule to the site, it automatically adds any document to the Drop Off Library. 

This form also gives you a warning that the document will be moved. Fill in the properties for this document, and make sure you follow the rules.  In our exmaple, we will add a “SA12” prefix to the Title of the document.  Next, click the submit button:

You will then receive a notification indicating where the document was routed to.  Note that if the document cannot be moved, whether there is an issue or if your conditions are not met, SharePoint will leave the document in the Drop Off Library.

In conclusion, the Content Organizer is a very cool feature in SharePoint 2010.  It allows you to capture a set of standard documents and route them to the proper destination, and the end user doesn't have to worry about where it should go.  This feature should be used in conjunction with Document IDs, Term Sets, and Metadata publishing in order to design an effective document management strategy for your SharePoint portal.

Notes:

The Content Organizer has the following limitations that you should beware of:

  • Content Organizer feature is only available in SharePoint 2010 Server and is not part of the SharePoint Foundation 2010.
  • Content Organizer will only work on content types that are of, or derive from the Document content type, so make sure that you inherit from this content type when creating a custom document library.
  • You cannot route documents to a Document Set.  This one should be on the wish list for the next release!
  • The routing action is performed using the App Pool account of your Web applications.
  • You cannot route the document outside of a Web app, farm, or SharePoint at all.  All of this could be done with workflow rules instead.  In fact, there are a lot of things that should be done with workflow instead of Content Organizer, which is designed to handle document uploads.
  • There are a whole bunch of events that effect a document library; you should beware the order of executions that could affect the handling of these documents:
    • Any workflow that is attached to a document library will be run first
    • Next to be executed is Event Receiver, although the actual priority can be set programmatically by the developers
    • Last is the Content Organizer.

Reference: http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2010/11/03/sharepoint-2010-cookbook-content-organizer-for-document-library.aspx

Tuesday, August 26, 2014

Understanding MVC, MVP and MVVM Design Patterns

There are three most popular MV-* design patterns: MVC, MVP and MVVM. These are widely used by the various technologies. In this article, I will provide my opinion on these three.

MVC Pattern

MVC stands for Model-View-Controller. It is a software design pattern which was introduced in 1970s. Also, MVC pattern forces a separation of concerns, it means domain model and controller logic are decoupled from user interface (view). As a result maintenance and testing of the application become simpler and easier.

MVC design pattern splits an application into three main aspects: Model, View and Controller

1.            Model

The Model represents a set of classes that describe the business logic i.e. business model as well as data access operations i.e. data model. It also defines business rules for data means how the data can be changed and manipulated.

2.            View

The View represents the UI components like CSS, jQuery, html etc. It is only responsible for displaying the data that is received from the controller as the result. This also transforms the model(s) into UI.

3.            Controller

The Controller is responsible to process incoming requests. It receives input from users via the View, then process the user's data with the help of Model and passing the results back to the View. Typically, it acts as the coordinator between the View and the Model.

Today, this pattern is used by many popular framework like as Ruby on Rails, Spring Framework, Apple iOS Development and ASP.NET MVC.

MVP pattern

This pattern is similar to MVC pattern in which controller has been replaced by the presenter. This design pattern splits an application into three main aspects: Model, View and Presenter.

1.            Model

The Model represents a set of classes that describes the business logic and data. It also defines business rules for data means how the data can be changed and manipulated.

2.            View

The View represents the UI components like CSS, jQuery, html etc. It is only responsible for displaying the data that is received from the presenter as the result. This also transforms the model(s) into UI.

3.            Presenter

The Presenter is responsible for handling all UI events on behalf of the view. This receive input from users via the View, then process the user's data with the help of Model and passing the results back to the View. Unlike view and controller, view and presenter are completely decoupled from each other’s and communicate to each other’s by an interface.

Also, presenter does not manage the incoming request traffic as controller.

This pattern is commonly used with ASP.NET Web Forms applications which require to create automated unit tests for their code-behind pages. This is also used with windows forms.

Key Points about MVP Pattern:

1.      User interacts with the View.

2.      There is one-to-one relationship between View and Presenter means one View is mapped to only one Presenter.

3.      View has a reference to Presenter but View has not reference to Model.

4.      Provides two way communication between View and Presenter.

MVVM pattern

MVVM stands for Model-View-View Model. This pattern supports two-way data binding between view and View model. This enables automatic propagation of changes, within the state of view model to the View. Typically, the view model uses the observer pattern to notify changes in the view model to model.

1.            Model

The Model represents a set of classes that describes the business logic and data. It also defines business rules for data means how the data can be changed and manipulated.

2.            View

The View represents the UI components like CSS, jQuery, html etc. It is only responsible for displaying the data that is received from the controller as the result. This also transforms the model(s) into UI..

3.            View Model

The View Model is responsible for exposing methods, commands, and other properties that helps to maintain the state of the view, manipulate the model as the result of actions on the view, and trigger events in the view itself.

This pattern is commonly used by the WPF, Silverlight, Caliburn, nRoute etc.

Key Points about MVVM Pattern:

1.      User interacts with the View.

2.      There is many-to-one relationship between View and ViewModel means many View can be mapped to one ViewModel.

3.      View has a reference to ViewModel but View Model has no information about the View.

4.      Supports two-way data binding between View and ViewModel.

 

 

 

Monday, August 25, 2014

Difference between WCF and Web API and WCF REST and Web Service

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use. Now a days, you have a lot of choices to build HTTP services on .NET framework. In this article, I would like to share my opinion with you over Web Service, WCF and now Web API. For more information about Web API refers What is Web API and why to use it ?..

Web Service

<![if !supportLists]>1.      <![endif]>It is based on SOAP and return data in XML form.

<![if !supportLists]>2.      <![endif]>It support only HTTP protocol.

<![if !supportLists]>3.      <![endif]>It is not open source but can be consumed by any client that understands xml.

<![if !supportLists]>4.      <![endif]>It can be hosted only on IIS.

WCF

<![if !supportLists]>1.      <![endif]>It is also based on SOAP and return data in XML form.

<![if !supportLists]>2.      <![endif]>It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.

<![if !supportLists]>3.      <![endif]>The main issue with WCF is, its tedious and extensive configuration.

<![if !supportLists]>4.      <![endif]>It is not open source but can be consumed by any client that understands xml.

<![if !supportLists]>5.      <![endif]>It can be hosted with in the application or on IIS or using window service.

WCF Rest

<![if !supportLists]>1.      <![endif]>To use WCF as WCF Rest service you have to enable webHttpBindings.

<![if !supportLists]>2.      <![endif]>It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.

<![if !supportLists]>3.      <![endif]>To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files

<![if !supportLists]>4.      <![endif]>Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified

<![if !supportLists]>5.      <![endif]>It support XML, JSON and ATOM data format.

Web API

<![if !supportLists]>1.      <![endif]>This is the new framework for building HTTP services with easy and simple way.

<![if !supportLists]>2.      <![endif]>Web API is open source an ideal platform for building REST-ful services over the .NET Framework.

<![if !supportLists]>3.      <![endif]>Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats)

<![if !supportLists]>4.      <![endif]>It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.

<![if !supportLists]>5.      <![endif]>It can be hosted with in the application or on IIS.

<![if !supportLists]>6.      <![endif]>It is light weight architecture and good for devices which have limited bandwidth like smart phones.

<![if !supportLists]>7.      <![endif]>Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.

To whom choose between WCF or WEB API

<![if !supportLists]>1.      <![endif]>Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.

<![if !supportLists]>2.      <![endif]>Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.

<![if !supportLists]>3.      <![endif]>Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).

<![if !supportLists]>4.      <![endif]>Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.

 

What is Web API and why to use it ?

Asp.Net Web API is a framework for building HTTP services that can be consumed by a broad range of clients including browsers, mobiles, iphone and tablets. It is very similar to ASP.NET MVC since it contains the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection. But it is not a part of the MVC Framework. It is a part of the core ASP.NET platform and can be used with MVC and other types of Web applications like Asp.Net WebForms. It can also be used as an stand-alone Web services application.

Why Asp.Net Web API (Web API) ?

Today, a web-based application is not enough to reach it's customers. People are very smart, they are using iphone, mobile, tablets etc. devices in its daily life. These devices also have a lot of apps for making the life easy. Actually, we are moving from the web towards apps world.

So, if you like to expose your service data to the browsers and as well as all these modern devices apps in fast and simple way, you should have an API which is compatible with browsers and all these devices.

For example twitter,facebook and Google API for the web application and phone apps.

Web API is the great framework for exposing your data and service to different-different devices. Moreover Web API is open source an ideal platform for building REST-ful services over the .NET Framework. Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats) and you don't need to define any extra config settings for different devices unlike WCF Rest service.

Web API Features

1.      It supports convention-based CRUD Actions since it works with HTTP verbs GET,POST,PUT and DELETE.

2.      Responses have an Accept header and HTTP status code.

3.      Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.

4.      It may accepts and generates the content which may not be object oriented like images, PDF files etc.

5.      It has automatic support for OData. Hence by placing the new [Queryable] attribute on a controller method that returns IQueryable, clients can use the method for OData query composition.

6.      It can be hosted with in the applicaion or on IIS.

7.      It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection that makes it more simple and robust.

Why to choose Web API ?

1.      If we need a Web Service and don’t need SOAP, then ASP.Net Web API is best choice.

2.      It is Used to build simple, non-SOAP-based HTTP Services on top of existing WCF message pipeline.

3.      It doesn't have tedious and extensive configuration like WCF REST service.

4.      Simple service creation with Web API. With WCF REST Services, service creation is difficult.

5.      It is only based on HTTP and easy to define, expose and consume in a REST-ful way.

6.      It is light weight architecture and good for devices which have limited bandwidth like smart phones.

7.      It is open source.

 

Understanding Relationship Between CTS and CLS

CTS and CLS are parts of .NET CLR and are responsible for type safety with in the code. Both allow cross language communication and type safety. In this article I would like to expose the relationship between these two.

CTS

CTS stands for Common Type System. It defines the rules which Common Language Runtime follows when declaring, using, and managing types. The common type system performs the following functions:

1.      It enables cross-language integration, type safety, and high-performance code execution.

2.      It provides an object-oriented model for implementation of many programming languages.

3.      It defines rules that every language must follow which runs under .NET framework. It ensures that objects written in different .NET Languages like C#, VB.NET, F# etc. can interact with each other.

CLS

CLS stands for Common Language Specification and it is a subset of CTS. It defines a set of rules and restrictions that every language must follow which runs under .NET framework. The languages which follows these set of rules are said to be CLS Compliant. In simple words, CLS enables cross-language integration.

For example, one rule is that you cannot use multiple inheritance within .NET Framework. As you know C++ supports multiple inheritance but; when you will try to use that C++ code within C#, it is not possible because C# doesn’t supports multiple inheritance.

One another rule is that you cannot have members with same name with case difference only i.e. you cannot have add() and Add() methods. This easily works in C# because it is case-sensitive but when you will try to use that C# code in VB.NET, it is not possible because VB.NET is not case-sensitive.

Why CTS is Called Common Type System?

In .NET, every Data Type is internally represented by a class or structure. All the classes and structures related to Data Types are collectively known as CTS. As you know every language provides its own keywords for Data Types but internally all the languages which run under .NET framework use the classes and structures available in CTS.

For example, C# has int Data Type and VB.Net has Integer Data Type. Hence a variable declared as int in C# or Integer in vb.net, finally after compilation, use the same structure Int32 from CTS.

All the structures and classes available in CTS are common for all .NET Languages and purpose of these is to support language independence in .NET. Hence it is called CTS.

What do you think?

I hope, you have enjoyed the article about CTS and CLS. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

 

How to restrict the '/_layouts/viewlsts.aspx' page from anonymous users or from specified users in SharePoint 2010

Add below specified location section in web.config at path:

 

C:\inetpub\wwwroot\wss\VirtualDirectories\1234\web.config

 

<location path="_layouts/viewlsts.aspx">

            <system.web>

                  <authorization>

                       <allow users="domainname\user1,domainname\user2"/>

                        <deny users="?" />

                        <deny users="*" />

                  </authorization>

            </system.web>

      </location>

 

 

 

 

if you want to apply settings on all web application/site collection then :

 

Create an xml file  as below:

 

<?xml version="1.0" encoding="utf-8" ?>

<actions>

 

  <add path="configuration">

    <location path="_layouts">

      <system.web>

        <authorization>

          <deny users="?" />

        </authorization>

      </system.web>

    </location>

 

    <location path="_vti_bin">

      <system.web>

        <authorization>

          <deny users="?" />

        </authorization>

      </system.web>

    </location>

 

    <location path="_layouts/login.aspx">

      <system.web>

        <authorization>

          <allow users="?" />

        </authorization>

      </system.web>

    </location>

 

    <location path="_layouts/error.aspx">

      <system.web>

        <authorization>

          <allow users="?" />

        </authorization>

      </system.web>

    </location>

 

    <location path="_layouts/accessdenied.aspx">

      <system.web>

        <authorization>

          <allow users="?" />

        </authorization>

      </system.web>

    </location>

 

 

  </add>

</actions>

 

 

After creating a file that contains XML statements similar to above, you would save the file in the \Config directory with a name in the format webconfig. <name>.xml. To apply these changes to the farm, run the Stsadm copyappobincontent operation on each front-end Web server. For more information, see Copyappbincontent: Stsadm operation (Office SharePoint Server).

 

 

Reference Links:

http://technet.microsoft.com/en-us/library/ee191479(v=office.12).aspx

http://msdn.microsoft.com/en-us/library/acsd09b0(v=vs.71).aspx

http://msdn.microsoft.com/en-us/library/8aeskccd(v=vs.71).aspx

Locking down Office SharePoint Server sites

http://www.c-sharpcorner.com/uploadfile/Roji.Joy/how-to-secure-external-anonymous-access-to-sharepoint-2010-sites/