Friday, March 15, 2013

SharePoint 2010 : URL Mapping issue


At times, when you are writing some code or accessing your site and want to use IP address to locate your SharePoint but you see the error below. Follow the steps mentioned to resolve your issue:

The Web application at http://your IP address could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application

  • Add the IP in the Access mapping in SharePoint Central Admin.
  • Select Alternate Access Mapping Collection as your team site.
  • Add Internal URL as your IP and select zone as Intranet.

Resizing an Image for consistency in SharePoint

While implementing intranet within our organization, we configure MySites within SharePoint, upload the user profiles from Active Directory and give users the ability to upload their own picture. Also, while implementing any News, or any company information, updates on the home page of Intranet, we tend to put pictures beside the text we write. Now, the image for several notifications can be of several size if you don’t have an in-house designer who trims/resizes your pictures to be uploaded to SharePoint. So, here comes my solution to resize images as we upload them to a definitive size which can then be uploaded and shown to users on the SharePoint.

I have created Synchronous event receiver to my Notification list where I am adding the image and the code resizes the image and uploads it to the list for a nice and consistent look and feel of your website.

Copy and paste the code below into your ItemAdded method.

       public override void ItemAdded(SPItemEventProperties properties)
       {
           int _imageWidth = 0;
           int _imageHeight = 0;

           if (properties.ListTitle.ToLower().Equals("intranet pictures"))
           {
               try
               {
                   string _width = properties.ListItem.File.Properties["vti_lastwidth"].ToString();
                   string _height = properties.ListItem.File.Properties["vti_lastheight"].ToString();

                   if (Int32.TryParse(_width, out _imageWidth) && Int32.TryParse(_height, out _imageHeight))
                   {
                       //checking if the image height and weight is 120 (for the sake of example)
                       if (_imageWidth != 120 || _imageHeight != 120)
                       {
                           SPFile _imageFile = properties.ListItem.File;

                           MemoryStream _inputStream = new MemoryStream(_imageFile.OpenBinary(), true);
                           MemoryStream _outputStream = new MemoryStream();

                           Image _resizedImage = Image.FromStream(_inputStream).GetThumbnailImage(120, Int32.Parse(_height), null, IntPtr.Zero);
                           _resizedImage.Save(_outputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                           _imageFile.SaveBinary(_outputStream, false);                          

                       }
                   }
               }
               catch (Exception ex)
               {
                   properties.ListItem.Delete();
                   properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                   //You can give the location of your custom error page here
                   properties.RedirectUrl = "/_layouts/Intranet_PictureRestrict/IntranetPicError.aspx";                   
               }
           }
       }
Let me know if you want to customize it more or have any queries.

Wednesday, March 13, 2013

SharePoint 2013 : Introduction to Event Receivers


I installed the beta version of SharePoint 2013 recently and played around with it. The first impression I had after creating team sites and community sites was “WOW, it looks amazing”. I guess that’s how you react every time you see a new offering of SharePoint J
This is my first post on SharePoint 2013; dedicated to something I use the most within SharePoint implementations, the Event Receivers.

As SharePoint 2013 offers App development as part of Office 365 development suite, which also replaces the traditional sandboxed solutions available in SharePoint 2010, it becomes very easy to create apps and maintain them within SharePoint 2013.

Event receivers are somewhat modified for SharePoint 2013 into two parts, namely 
  • Remote event receivers and
  • App Event receivers 
I will write separately about how to create both of these event receivers in my future posts. In this blog I will explain what they are and how they can be used to suit our business needs.

Remote Event Receivers

These event receivers signify events that occur on items within any list or library. Say addition of an item, update of an item or deletion of an item. They can be synchronous and asynchronous in nature. Microsoft has modified a bit in this version of SharePoint, the way we deal this nature of event receivers. We will see it how later in this post.

App Event Receivers

These event receivers signify the events that occur to the app we are creating. Say app installation, app uninstalling or app upgrading.

As we create a new remote event receiver or app event receiver in Visual Studio 2012, we need a web application where we would be deploying our app. By default the scope of the app will be the host web application mentioned. A web service is added to this web application to handle the events which contains two methods

ProcessEvent()
Handles events that occur before an action occurs, such as when a user adds or deletes a list item

ProcessOneWayEvent().ProcessEvent()
Handles events that occur after an action occurs, such as after a user adds an item to a list or deletes an item from a list

Like in SharePoint 2010, we had synchronous and asynchronous event receivers, in 2013; we have these two methods which deals with the nature of the event receivers.

Many other things remains same the way we used to deal with them in SharePoint 2010 and VS 2010 environment like adding more events within your event receiver solution, changing the event receiver to point to either Document Library or an Announcement list and so on.

I will write more as and when I try new things within SharePoint 2013.

Tuesday, March 12, 2013

SharePoint 2010 : Record Declaration


Record Declaration is one of the many new things introduced within SharePoint 2010. When implementing document management, we always come across scenarios where the final document is ready and we should lock it down so that no one can tamper with it and the document remains safe within the organization until it reaches its retention period. Such documents can be Staff files within an organization, any property related papers, insurance papers or so on. So, once we decide that the final version of any item within our SharePoint site is ready and we want to keep it for certain period of time without giving anyone the ability to change its content, we would prefer to lock it down and make it a RECORD.
Record declaration can be done manually or can be done as part of the Information Management policy within the document library. We will see how to create any item as record in this blog post. 
  • Manual declaration of Records

As we click on the Record declaration settings, we see three radio buttons:


Use the site collection default settings: Do not allow manual declaration of records
This will not allow users to declare the items as records manually from the ribbon button within the document library.

Always allow the manual declaration of records
This will introduce a ribbon button within the Document section (highlighted in the figure), clicking on this button will make the item as record and no more updates will be allowed on it any further.


Never allow the manual declaration of records
As name signifies, we cannot make the items as records by selecting this.

Also, we see the check box for automatically declare items as records as they are added to the list, checking this check box will make the items are records with no functionality to update the item in the future. This is very useful as we deal with documents which have just one version i.e., the final version.

Now we saw that either we can manually declare items as records which is very simple or we do it programmatically. But we can also declare records as part of the Information management policy within the document library.
  • Schedule the record declaration

We can schedule the record declaration by enabling the retention on the items. See Retention in SharePoint 2010 post for more details on how to implement retention to SharePoint items.

There may be a case where we would want to automatically declare items as records after a certain period (say Created Date + 2 years). This can be automated by the following way:

  • Click on Information management policy setting under Permissions and management in library settings.
  • Click on the content type of the document, you want to declare records.
  • Check the Enable Retention checkbox
  • Click on Add a retention Stage
  • Select Time period as Created + 2 years
  • Select Declare record in the Action drop down
  • Click Ok and save your retention schedule for the particular content type.


Similarly, as we applied the rule on content types, the same can be done to the folders as well if you have folders in your library.

Monday, March 11, 2013

SharePoint2010 : Calculated Columns


SharePoint calculated columns often become very useful while doing simple or I should say not so complex calculations within SharePoint fields. I have had requirements which are not an easy one and not even so complex that I should be writing some kind of custom code to implement them, where I find the use of SharePoint calculated columns very useful. While implementing the calculations, I browsed many books, blogs and MSDN forums and found the below mentioned link very useful.


I am sure this post will encourage you more to use SharePoint calculated columns where ever required as they are easy to implement and no maintenance required. 

Happy SharePointing !!

SharePoint2010 : Creating Surveys


Creating surveys and recording response in SharePoint is a very useful feature of any intranet or internet facing site. Surveys can be recorded periodically every quarter or monthly based on organizations. This blog post shows how to create a survey and record responses from the audiences. 
  • You must log on to your SharePoint site with admin rights.
  • Click on View All Site Content and click on Create 
  • Select Lists from the left and select Surveys from the list
  • Enter the name of your survey and click on Create.



Now that our list is created, it’s time to enter the questions for the survey. 
  • Enter your question and click on Next Question until you finish entering all your questions one by one. While filling in the questions, you can select the field type for each question and proceed. You can also branch your users according to their responses, how to do that, we will see later in this post.


Now that you have finished entering all your questions, you should click on Finish which will take you to the list settings page where you can see all your questions listed. Now, you can click on the question you want to put branching on and enter the branching criteria. Finally when all this is done, you are good to test your survey. Click on the survey list from the left hand navigation which will take you to the survey list. Click on Respond to survey for filling in the answer to the questions and submit your survey. Now, if you want the audiences to have only the survey submission rights and they should not be able to view what others are submitting, restrict access to the library accordingly.

Hope this helps

Friday, March 8, 2013

SharePoint2010 : Manually sending items to Record Center


Once you have followed my previous blogs




you are ready to proceed and send the items you wish to the Record Center.

To manually, send the items to Record center, click on the dynamic dropdown for the item. Hover the mouse on Send To and select your record center that you have created. That's it, SharePoint will do the rest as we have made our web application ready by creating Sent to connection and setting the content organizer rules.

Follow the screenshots for more clarity:







SharePoint2010 : Setting Content Organizer Rules within Record Center


Setting rules within the Content Organizer is required to route your documents to send to their destination library. For the interim period they can sit within the Drop Off library, and based on the rules we set, they are routed to their destination library. As we activate Content Organizer within our site, the Drop Off library is created by default. This post describes how we can set the rules to route our documents which we send to Record center.

  • Go to Site Settings > Content Organizer Rules under Site Administration.
  • Click on Add Item.


  • Fill in the name for the rule.
  • Select the Rule Status and Priority
  • Select the Content Type (make sure you have added this content type to your destination library)
  • Most importantly, select the condition on which the routing should occur next.
  • Finally, select the Target library clicking on the browse button.
There you go, the rules are set now. You are good to send documents to your Record Center which will come to its Drop Off library and then routed to your destination library.

Thursday, March 7, 2013

SharePoint2010 : Creating Send To connection


Follow the steps below once you have Created your Record Center. If you want to see how to Create Record Center, Click here.

Make a note of the Submission Web Service URL 
  • Navigate to your Record Center
  • Go to Site Settings
  • Click on Content Organizer Settings under Site Administration 


  • Select the Web URL and copy it to clipboard/notepad  (we will use it later)




Create Send To connection
  • Ensure that you have the required permissions to perform this procedure. To create a connection, you must be a member of the Farm Administrators group.
  • Go to SharePoint Central Administration, under General Application Settings, click Configure Send To Connections.

  •   In the Web Application field of the Configure Send To Connections page, select the Web application that hosts the site collections from which documents will be sent.



  • From the Send To Connections list, select New Connection.
  • In the Display name field, type a name for this connection. This is the name that users will see as one of the options to which to send a document.
  • In the Send to URL field, enter the URL which we copied in the initial steps. Click "Click here to test" if you want to confirm that you have entered a URL to a Content Organizer. This should bring you up the web service that transfers the document from source to destination.
  • To display this connection in the list that appears when a user clicks Send To, select Allow manual submission from the Send To menu.
From the Send To action list, select one of the following values:
  • Copy: Select this option to create a copy of the document and send the copy to the destination repository.
  • Move: Select this option to delete the document from its current location and move the document to the destination repository. Users will no longer be able to access the document from its original location.
  • Move and Leave a Link: Select this option to delete the document from its current location, move it to the destination repository, and leave a link at the current location indicating that the document has been moved. When a user clicks this link, a page will appear that displays the URL of the document and the document’s metadata.
  • In the Explanation dialog box, type the information to be added to the audit log when the user sends a document by using this connection. If you selected Move and Leave a Link in the previous step, the page that appears when the user clicks the link will also display the explanation.
  • Click Add Connection to create the connection.
  • Click OK.


SharePoint2010 : Introduction to Record Center

The Records Center is intended to serve as a central repository in which an organization can store and manage all of its records. The Records Center supports the entire records management process, from records collection through records management to records disposition.

When we are implementing Document Management within our organization, and we have thousands of documents to maintain within a library whereas many of them are historic, and we do not use them very often, it makes sense to keep them separate and not clog your library with huge number of items. Hence, SharePoint gives us the flexibility for document retention using Record center. We can create record center and send our documents to it once they are approved and are in their final version. Sending to Record center can be of three types mainly: 
  • Copy the document to Record Center 
  • Move the document to Record Center
  • Move to the document to Record Center and Leave a link
As per the business case, we can implement any of the above mentioned way to treat our items within the library. 

Steps to implement Document Management through Record center: 

SharePoint2010 : Create Record Center


Creating Record Center is very simple. It is just created like any other team site within SharePoint. 
  • Go to All site Content. Click Create 
  • Select Site > Record Center
  • Enter the desired display name and the URL for the record center
  • Click on Create


There you go!! The Record center is created and ready to use.
You might notice the Drop Off Library is listed on the left hand navigation which is a part of Content Organizer is activated by default. 

This is the temporary placeholder library where all the items when sent to the Record center using Send To connection are stored. We will have to set rules to this library to move our items to their destination library within the Record Center.

Wednesday, March 6, 2013

Applying Retention Policy to SharePoint 2010

Records Management is one of the very important aspects of SharePoint 2010 along with document management. Retention can be set either on content types or on folders depending on business case. In this post, I will explain how to set retention on any SharePoint library.
To start with applying retention to your library items, let us create a content type and then we will apply the retention to the content type which will drive the documents throughout their life cycle.
Now that we have our content type ready, document is in the library with valid value in the metadata field, we can proceed to apply retention to the content type.

Step 1: Click on Library Settings > Information management policy settings (under Permissions and Management)
Step 2: You can see the Vouchers content type listed along with the by default Folder content type. Click on Vouchers content type.

Step 3: Check the Enable Retention check box and click on Add a retention stage
Step 4: To trigger off the retention, our custom column (Voucher Date) which we added while creating the content type will be listed here. Select Voucher Date from dropdown and put 2 years (for the sake of this post). This is where you will put in your business case and fill in the value you want.
Step 5: Once we selected the Voucher Date and entered the number of years, now it’s time to select the kind of action we would want to perform on the item. The Action dropdown will list the available actions to choose from.

Let us declare the item as record after 2 years (for sake of this post).
Select Declare Record and click on OK.
Now you will be directed to the previous page with your event described as below. If you want you can add another stage of retention based on your organisation policy. For example, you would want to delete the item after keeping it for another 5 years after you have declared as a record. So you can add another stage here. Also, you may want to send the record to Record Centre after certain period, you can add that here by adding a new stage.
And we are done. We have now successfully applied retention to our content type.
You can follow the similar way to apply retention to any folder; the process is exactly the same, so I am not mentioning it in my post.

The SharePoint job which works in background to make the retention work is Information management policy job and Expiration policy job. They can be scheduled as per your organization policy going into the Central Administration > Monitoring > Review job definitions (under Timer jobs).


Create Custom Content Type in SharePoint 2010

Content Management is an integral part of SharePoint 2010. It helps organize your documents, items and records in a way you have control over its life cycle. We can define what fields we want to use in content types and their data types. Also we can apply validations on the fields within a content type. This blog post describes creation of a custom content type within the site collection and using it within the document library.
Step 1: Create a content type “Vouchers” with some metadata columns.
Go to Site Settings > Site Content Types (under Galleries) > Create.

Step 2: Create two additional columns within the content type.


Step 3: Create a document library named “Payment Vouchers”.


Step 4: Enable use of Content types within the library.
Go to Library Settings > Advanced Settings (Under General Settings) and select Yes for Content Types.

Step 5: Add our custom content type to this library.
Click on Add from existing site content types and select our newly created content type “Vouchers” from the list and click Add. Also, I will remove the Document content type available in this library by default to avoid any confusion.

Once we add the Vouchers content type and remove the Document content type, the New Item ribbon button in our library will look like below:

Step 6: Now we can upload some documents to this library.
Click on Upload Documents and browse your file to upload. Once the upload is done, you will be asked to fill in the metadata for our content type Vouchers.

If you note, we made Voucher Date as mandatory, which is marked as a red asterisk. After filling in proper metadata, click on Save to complete the upload. Content types can be very helpful when you have thousands of documents in the same library and you have many types of documents in it, so creating separate content types for them and saving them under their appropriate values with their respective metadata values can be very helpful within the organization. Also, content types are very useful when you have a similar kind of documents within your site in different libraries, so you can create a content type and re use it in all the libraries. Implementation of Retention schedules also is one key benefit of using own custom content types.

Tuesday, March 5, 2013

SharePoint 2010 : Query using SPMetal entity

In SharePoint 2010, we can use LINQ queries to search data within SharePoint site. In previous SharePoint versions, I tend to use CAML queries instead, which is an efficient way to look for items. However, LINQ queries are faster and simpler to implement.
For more information on LINQ queries: follow this URL
For using LINQ within SharePoint, Microsoft has provided a tool named SPMetal.exe which resides in the 14 hive folder. This tool generates an entity class which we can add to our Visual Studio solution to get intellisense and use the entity classes for fetching data from SharePoint site.

Using SPMetal.exe

Go to command prompt and navigate to
  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\bin
  • Type SPMetal.exe /web:http://sharepointsite /code:C:\MyLINQEntity.cs

Now if you open the file, we just created, you can see all the lists, libraries have their classes with content types mentioned. It might happen that some custom content types are replaces with Item which is by default behaviour; you can modify the content types for the actual ones (you will get it in the intellisense).

Now that you add your .cs file to your Visual Studio project, you can use it for fetching items in SharePoint site.

using (PropertiesEntityDataContext context = new PropertiesEntityDataContext(SPSiteAddress))
{
//creating object from the Entity
EntityList<legalcasedocumentset> documentSet = context.GetList<legalcasedocumentset>(libName);
var first3Items = from item in documentSet.ScopeToFolder(folderURL, true)
where item.Name == docSetName
select item;