Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Wednesday, November 13, 2013

Override redirect using EditItemWithCheckoutAlert


On an edit item link, you want to perform some operation and redirect to a page of your choice, write a small script on your page and override the EditItemWithCheckoutAlert function.
So when you click on the edit link, the EditForm.aspx opens.


This allows you to modify the fields and delete the list item. Once you perform your desired action, the dialog box is closed and you are redirected to previous view/default view. To override this, use the script below, modify it to suit your URL and put it in a CEWP/Script Editor WP on your page.



Tuesday, October 29, 2013

Converting InfoPath data connections to UDCX files

While working with InfoPath 2013 and SharePoint 2013 on a Windows 2012 platform, I came across an issue where I was not able to convert the InfoPath data connections into UDCX files. I was getting the error below:

The specified location does not exist or could not be opened. Choose a data connection library on a server running Microsoft SharePoint Server and specify a valid filename.


After some read through, I found out that for this to be able to work, I would need a Windows feature installed on the server. This feature is Desktop Experience. Once I enabled this from the Server Manager, and restarted the server, I got rid of this error. Files were then getting converted to UDCX and were published to the Data Connection library.



Hope this helps someone.

Thursday, September 5, 2013

Disabling mobile site within SharePoint 2010

As we all know that SharePoint creates a very basic (ugly looking) default site for mobile devices. When opening the site from any mobile browser, it automatically directs the website to the respective mobile website which has /m appended to it.
My client did not wanted the default mobile site to open within mobile devices as it gives a very untidy look so they wanted to disable the redirect function. If you have similar issues, follow the steps below to disable the redirection.
  • Navigate to:
    • C:\inetpub\wwwroot\wss\VirtualDirectories\<yoursharepointsite>\App_Browsers\compat.browser
  • Locate
    • <userAgent match=”iPhone”&gt
  • Now under <capabilities> tag, locate
    • <capability name=”isMobileDevice”    value=”true”/>
  • Change this to false
  • Now for Android, repeat the same thing and set the ismobileDevice attribute to false.

No need to reset the iis or anything else. Just save the file and browse the site from iphone, you will see the desktop site opening.

Also, I noticed that if you create a backup copy of the file with any name within the folder, the site breaks and doesn’t render. So make changes within the file and copy it to some other location for a backup copy.

There is a MobilityRedirect feature within the SPWeb which can be disabled to prevent the redirection as well.
  • Disable-SPFeature –Identity MobilityRedirect –Url <url>

Hope this helps someone

Thursday, August 29, 2013

Deleting work item in TFS using Visual Studio 2010

As I was setting up TFS (Team Foundation Services) for my upcoming SharePoint project, I created few work items such as Tasks, Sprint Backlog, Bugs etc. also created custom fields and values within them. To test these items, I created a few test work items before moving it to live. Now, I wanted to get rid of the test work items I created before I could log live data in it. So here comes this post, where I would write on how we can delete work items from TFS. So, first of all, there is no simple tick and delete UI from Microsoft which does so. Microsoft recommends using command line to delete the work items. There are some free tools available through few of the sites, but I prefer deleting using command line. Follow the steps below:
  • Open Visual Studio Command Prompt by navigating to Start > All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools
  • Note down the IDs of the work items you want to remove from the TFS
  • Within the command prompt type the below syntax:
witadmin destroywi /collection <your TFS site collection> /id:<id>,<id>,<id>

Note: For noting down the IDs of the work items you can run a query that has ‘test’ in the Title field, provided you have entered test while your testing.

Thursday, August 15, 2013

Resetting Sync databse within SharePoint

Resetting Sync database will delete the database completely with all the values in it.
I think one should reset the sync database as the last thing when all troubleshooting tricks provide no result. Only consider resetting when: 
  • Your import user profile connection is fetching details from AD but they cannot be seen on SharePoint
  • Similar scenario with export connections, so you want to push changes back to AD but you don’t see any changes on AD
  • You have modified settings on your FIM Client manually 

Here is a very nice article on resetting the sync database you should follow before considering a  reset:


PS: The User related information such as Profile Pictures, About Me etc. resides in Profile DB and the Social DB, these information will be safe as you do a reset of your Sync database

Monday, July 29, 2013

InfoPath dropdown with different Value and Display Name

InfoPath dropdown comes with an ability to have different values being sent to the list/database and a different value to be viewed by users. For eg., you bind a dropdown which fetches users from a SharePoint security group and you want to display the “Display Name” attribute of the user within the dropdown values at the same time you want to map this field to a People picker field within the list and for that purpose you want to send the “Login Name” attribute to the people picker field. In such a scenario, follow the screenshots to create a similar functionality.

Click on the Dropdown properties

Select the datasource from the Data source dropdown or you can create one here as well. Then click on the Select XPath button (highlighted in the image).
In the Entries field, select the parent node and click OK.
This will enable you to select two different values for the Value and the Display Name field.
Now from the returning values, select the ones you want for each field and save your form.
To view your changes, you may want to publish the form and verify the changes.

Tuesday, June 18, 2013

Using JQuery to hide SharePoint 2013 List Item fields

Hiding unnecessary fields in DispForm.aspx/EditFOrm.aspx is something most of us implement within our SharePoint implementations. Here is a quick way to achieve that using JQuery.
Hiding any List Item fields
So you have many fields in your NewForm.aspx but you want to hide some like in the screenshot. I want to hide the fields I haven’t underlined.



I will click on Edit Page, and add a Script  Editor webpart on the page. From the below script, just change the number in which your fields appear on the page using a 0 index. So to hide the first field, enter 0, second field – enter 1 and so on.



Also you can do some formatting on your page using Jquery, for example I am making the font as BOLD for the list item entries.
$(".ms-formbody").css("font-weight","bold");

Also,
I want to hide the information in the screenshot, you can add this line as well.


$(".ms-descriptiontext").css("display","none");
Hope this helps someone looking for a similar scenario.

Thursday, May 30, 2013

Mapping custom Active Directory fields to SharePoint


Many at times, I have been asked about mapping custom properties from Active Directory to SharePoint User Profile. I decided to answer them via this post.

Mapping fields from Active directory to SharePoint is very simple and straight forward. We will see a step by step demonstration now.

Go to your User Profile Properties, click on Manage Properties and Add Property


Enter the Name, Display Name, Type and Length of the field you are trying to map across to SharePoint (These attributes are for the SharePoint front). After entering these fields, as you scroll down the page, you will see the section “Add New Mapping”

Select the source of your AD Import from the dropdown, if you have just one AD Import profile, you will see that selected by default. 

In the Attribute text field, enter the property name which is at the Active Directory side. Then click on Add. You will see the attribute is added in the Property Mapping for Synchronization section.

That’s it. You are done. 


Click on OK and run a full synchronization. 

You will see your property being pulled from AD to SharePoint.



Wednesday, May 22, 2013

Retrieving SharePoint List Items using Javascript in a Custom Webpart


So you want to fetch list items but do not want any post back, yes we can implement that using Javascript within our custom webpart by using a client control. 

Let me explain that in a step by step process
  • Create a new Visual Webart Project in VS 2012.
  • Give it a proper name and make it a Farm level solution.
  • Now delete the existing Visual WebPart item within the solution (to remove the default name) and add a new item – Visual WebPart and give it the desired name.
  • Open ascx file and copy paste the code below
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1.ascx.cs" Inherits="TestJavaScript1.VisualWebPart1.VisualWebPart1" %>

 Test 




Here I am using client control and not any server control so there will not be any post back experience.
If you wish you can add more functionality to this same webpart and use it in your real world scenario like adding server controls to it and then writing some code behind for it and so on.

Thursday, April 4, 2013

Programatically breaking inheritance and adding unique permission to List Items


Permission handling is something which makes SharePoint a favorite product within the industry. SharePoint has Permission levels in built for basic roles, however you can create your own permission levels and assign to Groups and then set those groups to access any site/library/list. Whenever a sub-site is created, it asks you if you want to inherit the permission from the parent site or want to create unique permissions. 

If you choose to inherit the permissions, it will copy the same set of permissions to the sub-site which will again be passed on to the lists/libraries you create. It may happen that for securing our content, we want to break this inheritance and want to assign unique permissions to restrict the users for certain actions and to make the content more secure. Inheritance can be broken manually using the Out of feature also and if you have a business logic in place, you can do it programmatically also. This blog post gives you code to break inheritance for items meeting certain criteria and assigning permissions to them explicitly. I am using ItemAdded() event receiver to do this. You can use it within workflow or any custom webpart as well.

SPGroup securityGroup = spWeb.SiteGroups["Security Group Name"]; 
SPRoleDefinition groupRole = spWeb.RoleDefinitions["Read"]; 

SPRoleAssignment roleAssign = new SPRoleAssignment(securityGroup); 
roleAssign.RoleDefinitionBindings.Add(groupRole); 

SPListItem listItem = spWeb.GetListItem("http://List Item URL"); 
listItem.BreakRoleInheritance(true); 
listItem.RoleAssegnments.Add(roleAssignment); 
listItem.Update();

Monday, April 1, 2013

Creating Event Recievers within Visual Studio 2010

Event receivers can be broadly seen as of two types:

Asynchronous (triggered before finishing of previous event)
          ItemAdding, ItemUpdating
Synchronous (triggered after finishing the previous event)
          ItemAdded, ItemUpdated

Follow Steps to create an event receiver with Visual Studio 2010 and SharePoint 2010 :
  • Open up Visual Studio 2010 with administrator privileges
  • Click File > New > Project
  • Under Installed templates, click SharePoint and then select Event Receiver (C# in my case). Enter the name, storage location and Solution name in the text box provided and click on OK.
    • It will then ask you to specify the site and trust level or scope of your solution. If you want to deploy it across your farm so that all web applications can make use of it, you should select Deploy as Farm Solution. However, with event receivers, it is not usual so we will select Deploy as Sandboxed solution, which means it will only be accessible to the sites where we activate this feature.
    • Now it will ask you to select the type of Event Receiver you would like to create. In our case it would be List Item Events. Then select what item should be the event source, here we will select Document Library as we want to create an item in document library and want our event receiver logic to run after that. You may want to select Picture library or a list here or as per your business scenario.

    • Now, check the events you would want to code for within your receiver. For the sake of example, I will check An Item was Added which means it will automatically create a method stub for me with ItemAdded method. Now click on Finish.


    Our development IDE is ready to use now and you can see the method stub for ItemAdded being created already.

    Copy and Paste the code below to your solution.
    using (SPWeb web = properties.OpenWeb())
    {
        //Name is a metadata column within my document library
        //Checking if the Name field is equal to Test
        if (properties.ListItem["Name"] == "Test") 
        {//If it is
            // Populating the Title field with some value
            properties.ListItem["Title"] = "Event handler works"; 
            // Updating the ListItem to incorporate the change. 
            // Necessary step, without this  the changes are not pushed to ListItem
            properties.ListItem.Update(); 
        }
    
    }
    
    
    Some more useful methods which can be used are
    //Name of the Document Library
    string DocLibraryName = properties.ListTitle.ToString();
    
    //Getting the Item ID
    int ItemID = properties.ListItem.ID;
    
    //Collection of Role Assignments - required for controlling permission to the Item
    SPRoleAssignmentCollection roleAssignment = properties.ListItem.RoleAssignments;
    

    Build the solution and deploy it. Go to your SharePoint site and activate it(if not already activated) and create any document library and create an item with Name as Test and see your event receiver in action.

    This event receiver will fire on all the document libraries within your site where you have activated the feature, if this is not the intended behaviour, use
    if(properties.ListTitle.ToString() == "DocumentLibraryName")
    
    And write all your logic within your IF block.

    For any queries please feel free to email me. If this post helped you, please share it and benefit more and more fellow SharePoint developers

    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.

    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 : 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.