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

Jan 23, 2012

Lookup columns in SharePoint 2010

In the previous article, we have learned about basics of lookup columns and the disadvantages in lower versions of SharePoint.
In this article, we will discuss the capabilities of lookup columns in SP 2010.
Types
There are two types of lookup columns:
1. Lookup columns with an enforced relation
2. Lookup columns with an unenforced relation
Lookup columns with an enforced relation
In a lookup column with an enforced relationship (also called referential integrity), you can lookup single values and maintain the integrity of your data in the target list in one of two ways:
Cascade Delete When an item in the target list is deleted; the related item or items in the source list are also deleted. In this case, you want to make sure that all related items are deleted as part of one database transaction.
Restrict Delete When you try to delete an item in the target list, and it has one or more related items in the source list, you are prevented from deleting the item in the target list. In this case, you want to ensure that the related item in the target list is preserved.
Lookup columns with an unenforced relation
In a lookup column with an unenforced relationship, from the source list, you can lookup single or multiple values in the target list. Also, when you delete an item in the source list, as long as you have delete permission on the list, there are no additional delete restrictions or delete operations that occur in the target list.
Enhancements in SP 2010
In SharePoint 2010, three major enhancements are added in the lookup columns:
1.   Additional column to show
2.   Cascade or restrict delete options
3.   To allow duplicate values or not options
As described in these article, I will create two custom lists such as Operating systems and Asset details as shown below
In the Asset details list, we will create a column which has lookup column from Operating Systems list as shown below

Note: I have created enforce relationship in this with restrict delete option as shown above.Now, we will add an item to asset details list
Now I have added some more items with different lookup fields from it.
Now, we will try to delete the Windows Vista item from the operating systems list which has lookup in the asset details list.
Now, as per the relationship this cannot be deleted and we will get an error which shows that asset details and operating systems list are related and it cannot be deleted as shown below.
Now, we will check with Cascade delete option
As per the relationship, when an item in the Operating System list is deleted, then the related item in the Asset Details will be deleted as shown below
I have deleted Windows Vista and hence, the corresponding items are deleted in the operating system list as shown below
When the relationship is not set, deleting an item in the source list will leave a blank space in the target list as shown below (this is the case same in WSS 3.0 and MOSS 2007)



Hope, this article helped in understanding the lookup column capabilities in SharePoint 2010 easily.
Now, there is another question arises, is it possible to create a cascading drop downs using lookup columns in SharePoint?
For answer, see this article.

Jan 6, 2012

Creating and Deploying a Visual Web Part using Microsoft Visual Studio 2010

To know about the Basics of Visual web part, read this article before knowing how to create and deploy the visual web part using visual studio 2010.
We will create a Visual web part for uploading the document to the SharePoint document library.
At the end of this article, we will learn
     1.How to create and deploy a Visual Web part
     2.How to programmatically upload a document to the SharePoint Document library

Open the Visual Studio and create a Visual Web Part project as shown below

When you click OK, you will see a pop-up window which will ask for the SharePoint site where the web part is going to be deployed as shown below. Hence give the proper URL of the SharePoint site. Also select the option Deploy as a farm solution because, visual web part is not a sandboxed solution

Once clicked Finish, you will see the project created with all the necessary files (assembly, .ascx files, feature to be deployed, .web part file) for a web part in the solution explorer as shown below

Click on the .ascx file and in the design mode, drag and drop the controls (FileUpload Control and Button) as shown below and complete the design part
I have added a JavaScript code which we used in this article for validating the file being uploaded is only .doc and .docx file.

Now, we will go for the coding the functionality of the web part. I have added a code in the Button1_Click event (Upload) of the web part as shown below

In the above code, give the proper name of the Document Library. I have used the default document library “Documents”.
Now Build the application and check for the errors. Once the build is successful, our web part is ready to be deployed in the SharePoint site.
It is very easy to deploy the visual web part. See the screenshot below.

That’s it. We have deployed our solution to the SharePoint site, which we have mentioned during creating the project.
Now, we will use the web part in our share point page.
Go to the SharePoint page -> Edit Page -> Insert web part -> Categories -> Custom -> Select the web part created (in our case I have named visualwebpart1)

Once added, we will see our web part designed in the SharePoint site page.

I will select a file and click upload. The file will get uploaded into the document library mentioned in the code.

Once Clicked Upload, the document is uploaded into the document library as shown below.

That’s it! We are done. We have learned to create and deploy the visual web part in SharePoint 2010.


Jan 5, 2012

Basics of Visual WebPart in Microsoft Visual Studio 2010

In this article, we are going to discuss about an interesting feature of Microsoft which is called Visual Webpart.
Web parts play an important role in the SharePoint design and development.
In the lower versions of SharePoint, we have to write the code for designing the webpart and then the custom code for its function.
But with the introduction of Visual Studio 2010 and SharePoint 2010 improved the way of creating and deploying the web parts in SharePoint (which is drag & drop the controls and design easily).
What is Visual Webpart?
In simple words, visual webpart is the wrapping the web user control (.ascx page) within a web part. 
Hence, the Web Part class will load a User Control in the Web Parts CreateChildControls() method and this user control is what you can drag and drop your controls to design the webpart. The Visual Studio interface nicely makes these operations seamless and takes care of all the wiring for deployment.
I will diagrammatically represent the visual web part


Advantages
1. Design of the web part is very easy, since it involves only drag and drop of the controls
2. No need to use the STSADM commands for adding an deploying the solution to the SharePoint site, since it involves only single click to deploy the solution
3. When we want to alter the design or change the code due to some bugs, we can make the changes-> re-build the solution-> deploy from the development environment which will automatically make the changes in the SharePoint site and even in the web part added in any of the pages
See also, how to create and deploy a Visual Web Part using Microsoft Visual Studio 2010 in this article.

See also, how to create a Visual Web Part and deploy the solution in SharePoint 2010 in this article.

Jan 4, 2012

Implementing Federated Search Result (Twitter) in SharePoint 2010

In the previous article, we have discussed about the basics of Federated Search Results in SharePoint
In this article, we will discuss how to implement the Federated Search results in SharePoint 2010.
Steps
Go to Central Administration of the SharePoint Server -> Application Management -> Manage service applications
You will see a list of services. In that Select Search Service Application

Clicking on this, you will be re-directed to the Search Server Administration page. In the left navigation, you will see some menus as shown below. Select Federated Results in the left navigation menu.
You will see a page, where you will find options for creating a New Location for Federated search or you can import the FLD file through Import Location option.

Clicking on the New Location option you will see the following page, where we will configure your Federated Location as shown below

That’s it. I have added the FLD file at the end of the article, for download so that you can download and import the file and work on it.
Now, we have configured the New Location and hence we will use the created Federated Location in the Search Center.
I have created a Search Center as shown below. First give a search query and in the results page, we will add the Twitter Results federated location.


In the search result page, edit the page and you will see options for adding the web part as shown below


After adding the Federated Results webpart, configure the results as shown below.

That’s it. We are done. Save the webpart and give a search keyword and test. You will be able to see the results from the intranet and from the internet search results (here Twitter).
You can download the Twitter FLD file from here.
Enjoy SharePoint using!

Jan 3, 2012

Federated Search Results in SharePoint

In this article, we are going to discuss about another interesting topic called Federated Search which came up with the MOSS (Microsoft Office SharePoint Server), when Microsoft updated the Infrastructure in SharePoint.

What is Federated Search?
Federate - Characterized by unity or being or joined into a single entity
Federation allows users to send the same query (search keyword) to multiple independent repositories, and display the results from each in its own region on a results page.

Advantages
1. It is helpful, when the search data is stored in the multiple repositories or to display results from various locations
2. We can bring the results from various social networking sites (Twitter, YouTube, Flickr etc.,) and search engines (Google, Bing, Yahoo, etc.,) easily in our search results page
3. Displaying the results from various sites and search engines allows the user to view the results from different source in a single page
4. We can display different types of results like Sites, Images, Videos, etc., This allows the users to interact with the site more easily.

Disadvantages
1.If we are using this federated search results in a corporate intranet, then there will be security issue. This is because, all the search queries/keyword (which may be confidential to a company) will be sent to the search engines. This search engines will store the data for some time, even after querying the results.
2. We cannot crawl the results from the other sources (Search Servers) and store the index
Hope this helps you!


Also, read about Configuring a Federated Results for Twitter in SharePoint 2010 and using it in this article.

How to Remove “+ Add document" from a SharePoint 2010 Document Library

In previous article, we have learned how to hide the Select/ Deselect Check Box from a view in the list/libraries.
In this post, we will see how to remove the + Add document” option from the document library in SharePoint 2010.
We will get some scenarios where, we will display the document library I different view and in that, we don’t want this option to be shown to the users. Because, it will allow the users to upload the documents.
Suppose the below is the document library where we want to hide the Add document option
 
We can achieve this by the following methods
1.   Editing the WebPart
2.   Using SharePoint Designer(CSS)
3.   Using J Query
4.   By Permission level(Default)

1. Editing the WebPart
Go to Edit WebPart -> Tool bar Type -> Select NoToolBar option which will hide the Add Document option
2. Using SharePoint Designer(CSS)
Go to the designer and edit the page/webpart where you want to hide. Search for class=”ms-addnew” and change the style to Style=”display:none”
3. Using J Query
Add a CEWP and link the following J-Query in it and hide the CEWP webpart
$(document).ready(function()
{
$(‘#WebPartWPQ2 .ms-addnew’).hide();
});
4. By Permission Level (Default)
We can set the permission level for the document library to read only and hence the user with read only option in the SharePoint site will not see this option
We will get the following result

Jan 1, 2012

How to hide the Select and Deselect Check box in a List/Library in SharePoint 2010

We might have faced some situations where you want to hide the Select and Deselect Option Check Box in the SharePoint 2010.
This is required, when you create some views and want to display some items with out check box options.
Let’s discuss about this in this article.
Suppose this is the document library where I want to hide the checkbox

Go to the Modify view in the Ribbon
You will see all the options for customizing the list\library. Click On the Tabular View.
Here you will find that, “Allow Individual Item Checkboxes” option is selected.
Unselect the Check Box and you are done. Now, you won’t see the Check Boxes in the list\Library as shown below
We can do this in SharePoint Designer also.
Go to the List/Library and then to the view where you want to hide the checkbox. Find the below section (.ms-WPHeaderTdSelection) and make this property to display equal to none.

.ms-WPHeaderTdSelection
{
Display:none;
}
That’s it. We have learned to hide the checkbox in lists and libraries of SharePoint 2010 using default settings and also using SharePoint designer 2010.

Dec 26, 2011

How to hide the left navigation bar in the SharePoint

In this article, we will see how to hide the left navigation in SharePoint siteThere are many ways for hiding the left navigation in the SharePoint. Here is the simplest way to hide it.
1.   Master.FindControl("PlaceHolderLeftNavBar").Visible = false;
2.   Place a content editor in the page you want to hide the left navigation pane in the site and add the following code in the source editor which will hide the left navigation bar.

<style>
.ms-navframe
{
display:none;
}
</style>
That’s it. We have easily hide the left navigation bar with a simple code.

Dec 23, 2011

Programmatically Creating Site Backup in SharePoint

In the previous article, we have discussed about creating and restoring the SharePoint site using stsadm command.
In this article, we will see how to take the backup of the site using SharePoint Object Model.The below is the code that will create the backup of the site and log the information in a log file.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SiteBackUp
{
    public class SiteBackup
    {
        static void Main(string[] args)
        {
         siteBackup("http://servername:portnumber","SharePointSiteBackup");   
        }
        public static void siteBackup(string siteURL,string fileName)
        {
            try 
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using(SPSite objSite=new SPSite(siteURL))
                    {
                        using(SPWeb objWeb=objSite.OpenWeb())
                        {
                            bool currentSiteStatus=objSite.AllowUnsafeUpdates;
                            objSite.AllowUnsafeUpdates=true;
                            bool currentWebStatus=objWeb.AllowUnsafeUpdates;
                            objWeb.AllowUnsafeUpdates=true;
                            string comment = objWeb.Title+"- Creating Backup is completed";
                            SPSiteCollection siteCollection=objSite.WebApplication.Sites;
                            objSite.ReadOnly=true;
                            string time=DateTime.Now.ToString("dd-MM-yyyy");
                            string backupName= "D:\\SiteBackup\\Backup" + fileName+"_"+time+".bak";
                            siteCollection.Backup(siteURL,backupName,false);
                            objSite.AllowUnsafeUpdates=currentSiteStatus;
                            objWeb.AllowUnsafeUpdates=currentWebStatus;
                            if(objSite.ReadOnly==true)
                            {
                               objSite.ReadOnly=false;
                               siteBackupLog(comment);
                            }                        
                         }
                    }
                });
            }
            catch (Exception ex)
            {
                SPSite site = new SPSite(siteURL);
                if (site.ReadOnly == true)
                    site.ReadOnly = false;
                siteBackupLog(ex.Message);
            }
        }
        public static void siteBackupLog(string message)
        {
            string PathName = "C:\\SiteBackup logs\\";
            PathName = PathName + "Backuplog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".log";
            StreamWriter sw = new StreamWriter(PathName, true);
            sw.WriteLine(message + " - " + DateTime.Now);
            sw.Flush();
            sw.Close();
        }
    }
}

Hence, we can automate creating backup of the SharePoint site using code. Also, the whole code created in visual studio can be downloaded here.
Happy Coding!

Dec 20, 2011

Deploying Silverlight Application in SharePoint 2010

In the previous article, we have discussed about creating a simple Silverlight Application in Microsoft Visual Studio 2010.
Now, in this article we will discuss how to deploy the solution in the SharePoint 2010.
The New webpart feature added in the SharePoint 2010 and SharePoint Foundation 2010 is Silverlight which comes under Media and Content category.
The Solution of the Silverlight application produces a package with extension .XAP
Note: The .xap file is a package which consists of the solution created in the Silverlight Application
Hence, copy the XAP file in the SharePoint Document library and copy the shortcut (Link) of the file.
Now go to the page where you want to deploy the solution.
Insert the Silverlight webpart as shown below




Now, edit the webpart and in the URL property, browse for the .xap file copied from the Shared Documents or copy the shortcut URL as shown below


Now save the page and you will see the silverlight webpart created as shown below

So, when you click the Click this button in the webpart, you will see the message box “This is a simple silverlight Application”

That’s it, we have deployed the silverlight application in the sharepoint 2010. Enjoy.

Creating a Simple Silverlight Application in Microsoft Visual Studio 2010

In the previous article ,we have discussed about the basics of Silverlight and In this article, we will discuss how to create a simple silverlight application using Microsoft Visual Studio 2010.
Go to Visual Studio File ->New Project
                                           
Select Visual C# in projects -> Silverlight Application (I have used .Net Framework 4.0)
Now, you will see a pop-up window like this
This windows gives the options for the user to create a new web application within the solution so that, we can test the silverlight application created here.
Here in our project, SampleSilverlightApplication.web is the web application created and we also select the silverlight version here.
Once clicked OK, a new silverlight application will be created as shown below
You will two projects created in the solution one is to design and code the application and the other is to test the application.
MainPage.xaml contains the design part of the application and MainPage.xaml.cs is the code behind where you will write the business logic.
In the right side, you will see the ToolBox which consists of Silverlight Controls which you can use for designing the application.
Now drag and drop a Label and Button in the design part and Right Click on the control -> Properties to view the properties of the control


I have changed the properties of label and button

In the .cs file, you will see the NameSpaces for the silverlight application in specific has been added.
Now, we will write the code behind for the button event as
Private void button1_click (object sender, EventArgs e)
{
MessageBox.Show(“This is a simple silverlight Application”);
}

Now save the code and debug the application. The application will render in the web application created in the initial steps.

Important Note: Once you debug the code, you will find solution package with the extension .xap in the Client Bin folder which is present in the Web Application.

This package consists of all the functionalities which is created in the application. 
When you click on the “Click this” button you will see a MessageBox pop-up with the message showing message “This is a simple silverlight Application”





That’s it we have learned how to create a simple silverlight application using Microsoft Visual Studio 2010.
See also, how to deploy the created silverlight application SharePoint 2010 in this article.
The full code can be downloaded from here.