Wednesday, September 15, 2010

SharePoint2010 Modal Dialog Box

When the OpenDialog method is invoked the SharePoint adds a div element named “ms-dlgContent”. The dialog contents are rendered from the passed URL. The passed URL can be a link to the web or a custom page. Also, the dialog can open a List Form dialog (Add/Edit). Another div element named “ms-dlgOverlay” disables the user from clicking on the original page and thus, provides the user with a modal dialog.


The showModalDialog method takes 1 parameter; an object of the Class SP.UI.DialogOptions. The option object contains the width and height of the dialog, the URL of the page and the dialog CallBack method name.


Step 1. JavaScript function


<script type="text/javascript">


function OpenDialog() {

var options= {

url:"/sitepages/myscustompage.aspx",

width: 800,

height: 600,

dialogReturnValueCallback: DialogCallback

};

SP.UI.ModalDialog.showModalDialog(options);

}

</script>


Step 2. Call javascript function on click of any button or any your control.


<input type="button" value="MY Custom Page" id="btn_dialog" onclick=" OpenDialog();"/>


If you want to close dialog box after executing your function code then add following line before end of function.


SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancel Clicked');



Hide "Select or deselect" Checkbox from Web Part Title Bar

I was able to hide the checkbox from webpart title bar by adding the following CSS to my master page:


<style type="text/css">

.ms-WPHeaderCbxHidden{

display:none;

}

</style>


Using following style i was able to hide the arrow from webpart title bar by adding the following CSS to my master page:


<style type="text/css">

.ms-WPHeaderMenuImg{

display:none;

}

</style>


Hope This information helps you.

How to get currently logged in User through JavaScript In SharePoint?

Since JavaScript is very useful tool for processing code on Client Side, It saves lot of response time and becomes very efficient Following code extract is very useful in finding out currently logged In user in SharePoint programmatically.


If you are running the Client Object Model (ClientOM) from javascript, then you should load the "sp.js" file using the ScriptLink.RegisterOnDemand method (a static method). In a web part, I recommend calling this in your OnPreRender override.



<SharePoint:ScriptLink ID="get_spUser" runat="server" Name="sp.js" Localizable="false" LoadAfterUI="true" />



The script code that will call into the ClientOM must not run until the "sp.js" file is loaded. SharePoint provides a method to help with this and this method is part of init.js, meaning that you need not register any further script files from SharePoint. To run a method named Initialize, use the following call:


ExecuteOrDelayUntilScriptLoaded( getCurrentUser, "sp.js");


Here's is the code for getting curreent logged In user in javascript-



<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded( getCurrentUser, "sp.js");

var context = null;

var web = null;

var currentUser = null;



function getCurrentUser() {

context = new SP.ClientContext.get_current();

web = context.get_web();

currentUser = web.get_currentUser();

currentUser.retrieve();

context.load(web);

context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));

}


function onSuccessMethod(sender, args) {

var userObject = web.get_currentUser();

alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());

}



function onFaiureMethodl(sender, args) {

alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

}


</script>




The above code returns you the user object and displays user name and user login name. You can customize it as you want.

Monday, September 13, 2010

MOSS 2007 web site migration In SharePoint 2010

Introduction: Number of hurdles are faced while migrating a MOSS 2007 site to SharePoint 2010 site.

They can specially cumbersome if you are SharePoint novice. In this blog I have explained the walkthrough for migrating a MOSS 2007 site to SharePoint 2010 site.

Step1: Find the content database name of your site for doing

"Central Administration ->> Application Management ->> Contents Databases".

Step2: Go to "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Your site database name" and Copy database files .mdf and .ldf . Before you copy these files please stop SQL services.

Or You could alternatively take contents db database backup (.bak) of MOSS2007 site using SQL Server Management Studio 2005.

Step3: Restore your MOSS2007 content database or Attach your database files (.mdf and .ldf) using SQL Server Management Studio 2008 r2 or create new database and restore .bak file.

Copy your MOSS2007 content database database files (.mdf and .ldf) in " C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA".

Open SQL Server Management Studio 2008 r2 and Enter credential.

Right Click on "Database" and select Attach option.

New window popsup then select ADD button.

Select your mdf and ldf files and press OK.

Now Your database is attached.

Step4: Create new Web Application on Share Point 2010.

Open Central Administration.

Select Application Management. Then Select "Manage Web Application" under Web Application section.

Select New from top ribbon bar.

Enter port number, web application name and press OK.

After creation of Web Application remove the Content Database from the new web Application. Go to "Central Administration" then Click on "Manage Content Database"

Select your web application and then Click on Database name.

After open the content database setting page, change Database Status "Ready" to "offline".

Check "Remove Content Database" option.

After checking this option you get on popup and select "OK" then click on "OK".



Step5: Now use STSADM to add MOSS 2007 content db to this web application. I am using the Microsoft "Share Point 2010 Management Shell" follow following links,

Open Share Point 2010 Management Shell -Start ->> All Programs ->> Microsoft Share Point 2010 Products ->> Share Point 2010 Management Shell.

Step6: Type command

stsadm -o addcontentdb -url http://b2b-shp10-dev:7000/ -databasename "WSS_Content_4784ff3a970149c292fe23be30d56424"

Step7: If your old database version and new database version are same then your database successfully attached if not then you can get following error.

Step8: Then go to your SQL Server management studio and Type following query for updating version of your database.Use suggested verion by screen or higher .

UPDATE [WSS_Content_4784ff3a970149c292fe23be30d56424].[dbo].[Versions]

SET [Version]='12.0.0.6421' WHERE[VersionId]='00000000-0000-0000-0000-000000000000'

Check version using select command

Step9: Re-executes the stsadm command.


Step10: If you get error like "Upgrade Completed with error...." then ,Redeploy all custom web parts.

Step11: Open Site in Browser.

Step12: It shows old User Interface. For new Share Point 2010 user interface follow following steps

Go to "Site Action ->> Site settings"

Select "Visual Upgrade" under the "Site Collection Administration" section

Select "Update all Sites" option

After that you can see new User Interface(UI) on your screen

Hope this information help you.

Thanks.