Monday, February 27, 2012

SharePoint 2010 VIDEO 
[ How to play it without using any third party tool ]

In my first SharePoint project, there was a requirement to play a video which has been added into the assets library (basically you can upload videos into this [will talk more about this type later] ) with in a custom web part (visual web part). playing video through the web is not a big deal, but in here requirement was, you cannot use any third party tool (like Flash player) on this.

If you are work in SharePoint 2010, you can use mediaplayer JavaScript to do that (I'm not sure that same JS is exist in SharePoint 2007 or 2003 ).

How to DO that ??


First you need to add hyper link to bind the video link (which taken from assets library). then put it in side a div tag, which ID should be "mediaplayer"



<div id="mediaplayer">

   <asp:HyperLink ID="HyperLinkVideo" runat="server">
                    <asp:Label ID="labelNewsVideo" runat="server"></asp:Label>
   </asp:HyperLink>

</div>


In here you can see that I have put my hyperlink in side a div tag which ID is mediaplayer (this is mandatory because, in the mediaplayer.js, identify the video link through this). and label (asp:Label) is use to show the video title or name.
then first of all you need to bind the video link and the name in to the required fields.


                try
                {
                    SPWeb rootWeb = SPContext.Current.Web;
                    // create sharepoint list object to get the newsletter data
                    SPList vidlist = rootWeb.Lists[VID_LIB_NAME];

                    // configure the query with the List item collection
                    SPListItemCollection vidItems = vidlist.GetItems(query);
                    // check whether the first item is null
                    mediaplayer.Visible = false;
                    ErrorMsg.Visible = false;
                    if (vidItems.Count != 0)
                    {
                        mediaplayer.Visible = true;
                        // display the required detail.
                        labelNewsVideo.Text = (vidItems[0]["Title"]==null) ? vidItems[0].Name : vidItems[0]["Title"].ToString();
                        // set the Document URL in to the link
                        HyperLinkVideo.NavigateUrl = vidItems[0][SPBuiltInFieldId.EncodedAbsUrl].ToString();                      
                      
                    }
                    else
                    {
                        ErrorMsg.Visible = true;
                    }
                }
                catch (Exception ex)
                {

                    ErrorMsg.Visible = true;
                }


you can see how to get the video link and assign it into the hype link through the hi-lighted area.

Then you need to implement JavaScript part in to the code. please refer the following code block.


<script type="text/javascript" src="~sitecollection/_layouts/mediaplayer.js"></script>
    <script type="text/javascript">
        _spBodyOnLoadFunctionNames.push('mediaPlayer.createOverlayPlayer');
        mediaPlayer.attachToMediaLinks(document.getElementById('mediaplayer'), ['wmv', 'avi', 'mp3']); 
    </script>


First You need to bind the mediapayer.js file with the web part, then use following code to push the required video detail in to the JS function (refer the hi-lighted are ). also you can define which type of videos that you need to play (in here i have assign wmv,avi and mp3)so all-together code block is like this.


<td class="WB_FormatHeading">
            <div id="mediaplayer">
                <asp:HyperLink ID="HyperLinkVideo" runat="server">
                    <asp:Label ID="labelNewsVideo" runat="server"></asp:Label></asp:HyperLink></div>
        </td>
    </tr>
    <script type="text/javascript" src="~sitecollection/_layouts/mediaplayer.js"></script>
    <script type="text/javascript">
        _spBodyOnLoadFunctionNames.push('mediaPlayer.createOverlayPlayer');
        mediaPlayer.attachToMediaLinks(document.getElementById('mediaplayer'), ['wmv', 'avi', 'mp3']); 
    </script>


Now you ready to go. after to deploy this.


when you click the video link it'll play with nice popup (good part is you don't need to install any third part tool like flash player).

ok That's It ... 
HAPPY CODING


Wednesday, February 8, 2012

Creating An ANONYMOUS Site in SharePoint 2010 
[Extended Approach]


In my second project at Navantis, I was asked to create as ANONYMOUS site, by using authoring site (Admin/Intranet Site). I was new to the SharePoint (still I am..), but i could be able to ask from someone, how to create it, or for sure I could be able to surf the internet and finished the task blindly. but I didn't do that. because the first question which come to my mind is. Why people need Anonymous site. why is that so important, What type of approaches we take to create them. and what is the best available approach for me to complete what i was assigned.

Why We Need Anonymous sites ??
people need information pools, that anyone can come to it, Use it and leave it with out been registering. or simply without been tracking. best example when you think about all the search engines like Google or Yahoo which provides service for billions of people. then interface of them, which use you and me, it's an Anonymous. which means. everyone can access with out been registers or with out been a member. that's why it's o important.

One of the best thing on these anonymous site are, you cannot control them. Only thing that you can do is, You can get the service out of them, that's it no big deal. but every Anonymous site4 has it's own admin interface of admin site. the people who got privileged, they are the people who do needful modifications, adding features, do maintenance, etc ..

What type of Approaches we take to Create Anonymous Site ??  
it's depend on the scope of the project, the time line and the requirement.
  • Create separate Anonymous site similar to Admin site and set the permission.
I this approach, we are creating a separate site and also we deploy our WSPs separately. then we set the permission. but this is not a good technique. because there are couple of drawbacks. first thing is, the modification (specially in the designing level) which do for the admin site will not be reflected in the Anonymous site (coz it's a separate site). Every time you need to populate you changes you have to do it separately, it's required more time and resources. [I don't recommend This approach]    
  • Extend site (Anonymous) using, Admin Site and set the permission.
In this approach, we are also creating a separate site. but instead of deploying WSPs and restore list items manually. We just extend the features and functionality from the mother site or Admin site. The best advantage it. when you do some modification or even you fill the data for particular list, all of the are reflecting in the anonymous site. Than's why I took this approach to address my task.
 The EXTENDED APPROACH 

Prerequisites
  • Admin site should have been already created. 
  • user should have necessary privileged in central admin and the admin site. 
The Approach
Open the Central Administrator (you should have privileged to CA). Start > All Programs > Microsoft SharePoint 2010 Products> SharePoint 2010 Central Administration.

then you can see the Central Administration panel


Select Manage web application under the Application Management.


Then in the Application management panel Select the Admin Application Which you need to create Anonymous site by extending. when you select it you'll see that there's a Extend button which located in the top corner in the ribbon. 



when you click it. you'll get a pop up to create web application. in there insert a port number which you need to create Anonymous Application then select select YES option under the Allow Anonymous Section. then click "OK"


Then it's take few second to create the Anonymous Web application. but in here you can't see the newly added web application in the panel, because it's an extended one. not the separate one.


Setting The permission.


Login to the created site as site owner.
Click the site permission link. And click anonymous access. 

Select as above and click [OK] button to see the site.


Now you complete the process and you'll be able to see the different between Authoring site and Anonymous Site.


When you logging to the Authoring site you'll see the Ribbon and Logging panel also you can do the editing stuff with in the site.   




When you access the Anonymous Site.You don't get those features like ribbon and logging panel etc..





ok That's It ... 
HAPPY CODING

Wednesday, February 1, 2012

Backup and Restore a SharePoint Site Collection 

Software development industry which develop projects based on SharePoint 2010, now trying to move into new approach what we called "Backup and Restore" rather than stick with the traditional approach where you create all the list site and other stuff with in the SharePoint project (VS project). specially when you are in a mid scale project time is a crucial factor and your client always expect to see something alive in daily basis.
When I join to the Navantis, my first project client wanted to finished it with in 4 weeks. Then, Navantis has decided to take Back up & Restore approach (which they haven tried before here in Sri Lanka).

In this approach, you are always asked to use, Out of the Box features (OOB). When you create list with in the site collection, when you create pages with in the site collection, master pages styles, almost everything including Data view web parts (by using SharePoint Designer). but if you are using some custom web parts, then you have to deploy them separately.    

How to take a backup of a site collection.

Open the Central Administrator (you should have privileged to CA). Start > All Programs > Microsoft SharePoint 2010 Products> SharePoint 2010 Central Administration


then you can see the Central Administration panel
Using SharePoint 2010 Central Administration Web site, under Backup and Restore, click perform a site collection backup



Then You get a Backup panel which has two main fields, which mandatory to be filled.
1) Site Collection path.
2) Backup path (where to save the Backup file)
and there is a option to select whether we are going to overwrite the existing file or not.
through the upper coner drop down you can choose the site collection path which need to be Backup. then choose the site collection path (even if it's in the manage path). 

After that you need to enter the Site collection backup file path. Eg: C:\SharepointBackup\port80.bak, then click ok. But there are some concerns on this path.
1) The folder (in here SharepointBackup) should have Write privileged. (other wise you'll get an Error when the service is started.)  
2) Backup File name should have .bak extension.
3) If a Backup File already exist on the current lactation with a same name then you need to check the "Overwrite existing file" option.

then you can see the backup service is starting.
Initially there are two options refresh and delete the job. if something going wrong with the backup or you accidentally click ok button then you can delete the backup service job.

but when the service got started. then you have to wait. and by clicking refresh button you can see whether service job finished or not.

when it get finished. then you can go to the location, where your file should be saved then you can see you backup file has been created.
This is how you can take entire site collection back up, which contain all the files and settings, but as I mentioned earlier, If you got any custom Web parts in your site collection. then you need WSP file also for restoring process . 

How to RESTORE a site collection using Backup File.

Restoring is also a easy process like the backup process. but you need to concentrate many factors when you are going to restore the backup file in to a new environment.

The following SharePoint Server Configuration should be exist on the server.
1)SharePoint farm version number should be equal or above, Means that sharePoint version number of the restoring server environment should be equal of higher than Backup server environment. 
NOTE :
Using PowerShell - (get-spfarm).BuildVersion command then we can get the version number 

PS C:\Users\thilinak> (get-spfarm).BuildVersion
Major Minor Build Revision
-----  -----  -----  --------
14     0      4762   1000

Version number:  14.0.4762.1000

2)SharePoint should run the Profile Synchronization Service Application and User Profile Service.
3)Other features (Eg: Language Packs), if Required need to be installed in the Restoring environment. 

NOTE:
Using SharePoint 2010 Central Administration Web site, under Upgrade and Migration, click Check product and patch installation status 


Once you are done with the initial configuration. we need to create a web application. on restore SharePoint environment. Or if you are going to restore it into the same application then you need to creat a Manage path . but make sure that, the path which you are going to restore should be empty (No site collection Existed ).
NOTE:
Create Managed path in the Production web application (if it is not already exist or created)
Using SharePoint 2010 Central Administration Web site, under Application Managment, click Create Site Collections. 
Then Go-to the Define Manage paths to create one. Give a name to the path “eg : Main” select type as Explicit inclusion , the added it and click ok.

Restore Back up file in to the manage path or Root path.
Using PowerShell – 
restore-spsite -identity http://sharepointqa.example.com/main/ -path C:\ExampleIntranetBackup\  ExampleIntranetUATProductionRLS01\ ExampleIntranetBackup.bak
Then you will get the message asking the restore options. Give A for that (yes to all)
 (replace “http:// ExampleIntranet.camoplastsolideal.com/main/ “ with valid production URL and replace “C:\ ExampleIntranetBackup\  ExampleIntranettUATProductionRLS01” with production back up file location)
Confirm
Are you sure you want to perform this action?
Performing operation "Restore-SPSite" on Target
" http://sharepointqa.example.com/main/ ".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):A

Wait till the restoring process is finished (if the process is successful it will display root path without given any red warnings)

If there is a site collection already exist in the given manage path then, we need to do the restoring process with overwrite command. (-Force)
[Warning: This will overwrite content and everything. You might lose any existing content. Which not include in the back up file. ]

Using PowerShell – 
restore-spsite -identity http://sharepointqa.example.com/main/ -path C:\ExampleIntranetBackup\  ExampleIntranetUATProductionRLS01\ ExampleIntranetBackup.bak -Force
Then you will get the same message asking the restore options. Give A for that (yes to all)
Confirm
Are you sure you want to perform this action?
Performing operation "Restore-SPSite" on Target
" http://sharepointqa.example.com/main/ ".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):A


When you got any wsp (which contain custom web parts and other required dlls), then you should deploy it into the application. 

WSP Deployment.

Add the required wsp (Internet.SharePoint.wsp) into the system using PowerShell – 

add-spsolution -literalpath 'C:\Backup\ UATProductionRLS01\Internet.SharePoint.wsp'  
(C:\Backup\ UATProductionRLS01\Internet.SharePoint.wsp is the wsp path)
Then using SharePoint 2010 Central Administration Web site, under System Settings, click Manage farm solutions. Verify that wsp was added. 
Deploy Required WSPs on production application. 
SharePoint 2010 Central Administration Web site, under System Settings, clicks Manage farm solutions. Then click on WSP which need to deploy. Clicks Deploy Solution


Select application which you need to deploy (eg: http://sharepointqa.example.com) clicks ok
Now you are done with the restoring process. but event you are done you might not be able to access the site,Backup file which extract form development environment might include development users (who exist in different domain) as site collection administrators. So we need to replace them with production administrators.

SharePoint 2010 Central Administration Web site, under Application Management, clicks Change site collection administrators.  Then select the site collection. And change the Administrators.

 Then you can access the site with admin account.

ok That's It ... 
HAPPY CODING