Thursday, March 8, 2012

Disabled Right click, CTRL + A, C, V using JavaScript in SharePoint


You want user to avoid copy, Paste data from SharePoint site, use the below script in CEWB. It will prevent user to right click, and Copy, Paste data from SharePoint page

<script type="text/javascript">
    var message="Sorry, you do not have permission to right click.";

    function clickIE4(){
    if (event.button==2){
        alert(message);
        return false;
        }
    }

    function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
            if (e.which==2||e.which==3){
                alert(message);
                return false;
                }
            }
        }
        if (document.layers){
            document.captureEvents(Event.MOUSEDOWN);
            document.onmousedown=clickNS4;
            }
        else if (document.all&&!document.getElementById){
            document.onmousedown=clickIE4;
        }
        document.oncontextmenu=new Function("alert(message);return false")
</script>

<script language="JavaScript1.2">

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

Auto Log Off after 10 min in SharePoint site


Some time users are required auto log off the SharePoint site after particular time for security. Here is JavaScript to add in CEWB on page.

You can set time in JavaScript and called the default Sign Out page of SharePoint. If you want to set auto log off for one particular page, set the below JavaScript function in CEWB on that page, otherwise for whole SharePoint site add the JavaScript function on master page.

<script type="text/javascript">
//Added for Auto LogOFF after 10 min


    function Timeout(){
        var t = setTimeout("RedirectToLogout()", 10*60000);
    }
    function RedirectToLogout(){
       var path = "http://YouSite/_layouts/SignOut.aspx";
       window.navigate(path);
    }
    </script>
<script>
  window.onload=Timeout;
</script>


Happy Coding 

Wednesday, August 3, 2011

Recover SharePoint Site from suspect database

 When Central Administration in SharePoint 2010 stops abruptly and its Content/Config database switches itself automatically to Suspect mode for no apparent reason, that too after a very stressful and super-hard working day for me.


To recover your sharepoint site from suspect database use following steps:-


1. Go to your MSSQL\Data files that reside under: C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

2. Identify your Central Admin Content Database name in my case it got screwed up and was in the suspect: mode: so this is my content database name WSS_Content_13885.

NOTE: Please take a backup of the corrupted .mdf and .ldf files, before following other steps

3. Open your SQL Server Management Studio ->, New Query and it opens up your SQL Query editor, copy and paste the query below and change the highlighted to your database name

--Verify whether Database has any issues
EXEC sp_resetstatus
"WSS_Content_13885"

---Alter database and put it on Emergency Mode
ALTER DATABASE "
WSS_Content_13885" SET EMERGENCY
DBCC checkdb
('WSS_Content_13885')

--Set the database in the Single User mode
ALTER DATABASE "
WSS_Content_13885" SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--Repair the database and allow data loss
DBCC CheckDB
('WSS_Content_13885',REPAIR_ALLOW_DATA_LOSS)

--Set the database back to Multi-User mode
ALTER DATABASE
"WSS_Content_13885" SET MULTI_USER

--Ensure Database is reset
EXEC sp_resetstatus
,WSS_Content_13885'.

Execute all the commands in your SQL Query Editor and there you go, Go back to your SQL Management Studio and you can see that the (Suspect) mode issue against the Content/Config database is fixed and the database got fully repaired and restored.

To verify the same, hit your Central Administration and it starts working just fine...

Thursday, December 16, 2010

How to identify a SharePoint Site?

We have lot of websites in internet and many of them are in SharePoint. So if you see any good looking site on internet and you want to check whether it is sharepoint based site or not?

There are some really cool exceptional ways.

Take "View Source" from any browser of your site. You will see something like <head> <meta name = "Generator" content="Microsoft SharePoint"/>

Dont forget to check Javascript section just after <Title>

You will see reference JS from src="/_layouts/1033/init.js"

If its SharePoint site there are also webservice with it. You can call any of webservice (If banned you will see "Unknown Error" page). e.g http://SharePointSite.Microsoft.com/_layouts/Lists.asmx .

Otherway is check images folder available in 12 hive folder(e.g. http://SharepointSite.Microsoft.com/_layouts/images/accesssetting.gif), it will show you image available in 12 hive folder.
           

Monday, December 13, 2010

Session State Error in SharePoint 2010

ASP.NET session state may be used on SharePoint 2010 pages. This service is automatically disabled in normal installations of SharePoint 2010. To enable session State in SP 2010 follow beleow steps:-
    • Enter the following PowerShell command in the SharePoint 2010 Management Shell window:
      Enable-SPSessionStateService –DefaultProvision.
    • Steps for PowerShell:-
    • Go to all programs-->Microsoft SharePoint 2010 products-->SharePoint 2010 Managment Shell.
    • On each web application for which you want to use session state, edit the web.config file and set the enableSessionState property of the pages element as follows:
      <pages enableSessionState="true".

Friday, December 10, 2010

Session Error occur on SharePoint Site

Some times Session error occur on your sharepoint portal server when installing asp.net project/User Control on SharePoint Server. The user control handling some session value on that page.

To overcome the error used following steps:-
1.       Go to Central Admin à Application Management à Configure Session State à enabled session state.
2.       From a command prompt, navigate to the Microsoft.NET 2.0 Framework directory(C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG).
3.       Open web.config file and modified as follows:-
4.       Uncomment the line:- <add name=”Session” type=”System.Web.SessionState.SessionStateModule” />
5.       Modified the line:- <pages /> to <pages enableSessionState=”true” … />
6.       From a command prompt:- change c:\Documents and setting… to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
7.       Run the command:- aspnet_regsql.exe -S  <server_name>  -d <database_name>  -ssadd  -sstype c  -E
8.       Where server name = is the database server where your database is located (Mentioned in error page).
9.       Where database name = is the content database of your shared services provider(Mentioned in error page.
10.   Make IISReset.

Tuesday, October 26, 2010

Calculated columns cannot contain volatile functions like Today and Me

When you trying to add calculated formula in list based on current date. You add '[Today]' in your formula and you give error like:- "Calculated columns cannot contain volatile functions like Today and Me". See image below:-




To solve this error use following steps:-

  1. Open up the List Settings page where you want this column.
  2. Create column named “Today”. The type doesn’t matter here, so let type as “Single Line of Text” and just click “Ok” 










3. Now create the calculated column where you need to use current date within formula and add “Today” from available columns.


















4.Once this is done, we no longer need that our own generated column “Today” so you can delete it (Although when you need to edit formula you will need this again, so either recreate this dummy Today field or make it hidden using code behind. Otherwise SharePoint will put you again on that error screen).






5.For calculated fields, calculated value is stored in Database when item is created at first time and doesn’t change until item is edited. So using Today doesn’t means each time you will get value re-calculated as per actual today’s date. For that it is better to use Computed column.