Wednesday, July 27, 2011

Timer Job With Trick

Timer Job our good old friend, for further details or quick start take a look at this http://technet.microsoft.com/en-us/library/cc678870(office.12).aspx 

A little know trick I have implement in my timer job so that it install only on Web front end or Single server (ex. DEV box, usually all in one box).

const string JOB_DEFINITION_NAME = "EscalationTimerJob";

public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
  SPSecurity.RunWithElevatedPrivileges(delegate()
  {                     
   #region ONLY WebFrontEnd/SingleServer
   SPSite site = properties.Feature.Parent as SPSite;
   SPWebApplication webApp = site.WebApplication;

   //make sure job isn't already registered
   if (webApp == null)
   {
    throw new SPException("Error obtaining reference to Web application.");
   }
   foreach (SPJobDefinition job in webApp.JobDefinitions)
   {    if (job.Name == JOB_DEFINITION_NAME)
       job.Delete();
   }
   foreach (SPServer server in SPFarm.Local.Servers)
   {    if (server.Role == SPServerRole.SingleServer || server.Role == SPServerRole.WebFrontEnd)
 {
  //Install the Job                        
  WorkflowEscalation taskJob = new WorkflowEscalation(JOB_DEFINITION_NAME, webApp, server, SPJobLockType.Job);
  SPHourlySchedule schedule = new SPHourlySchedule(); //Every Hour
  schedule.BeginMinute = 0;
  schedule.EndMinute = 59;
  taskJob.Schedule = schedule;
  taskJob.Update();
  }
}
#endregion
});
}


Note:
1. Added RunWithElevatedPrivileges, so that job definition will be create when activated even without full access. Feature activation runs under the application pool account. So it needs to be a farm administrator which will be mitigate by implementing RunWithElevatedPrivileges

2. Also make sure you also implemented below in your main execute() file
public WorkflowEscalation(string jobName, SPWebApplication webApp, SPServer server, SPJobLockType targetType): base(jobName, webApp, server, targetType)
 {
  this.Title = jobName;
 }

Usual code for installing in on all the servers:
const string JOB_DEFINITION_NAME = "EscalationTimerJob";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(
delegate()
{
  #region For Multiple Servers
  SPSite site = properties.Feature.Parent as SPSite;
  //make sure job isn't already registered
  if (site.WebApplication == null)
  {
   
throw new SPException("Error obtaining reference to Web application.");
  }

  foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)

  {
   
if (job.Name == JOB_DEFINITION_NAME)
      job.Delete();
  }

 
//Install the Job                    
  WorkflowEscalation taskJob = new WorkflowEscalation(JOB_DEFINITION_NAME, site.WebApplication);
  SPHourlySchedule schedule = new SPHourlySchedule(); //Every Hour
  schedule.BeginMinute = 0;
  schedule.EndMinute = 59;
  taskJob.Schedule = schedule;
  taskJob.Update();

  #endregion                                     
  });
}

Wednesday, March 16, 2011

Customizing the Access Denied Message (AccessDenied.aspx)

Request from client to customize the default access denied error message!!
By Default:

After Customizing the accessdenied.aspx page:
Note: If you want to be more fancy, you can replace the simple.master page with your own master page!














Parts been customizable as show:















Achieved by modifying 2 files


1. SharePoint resource file wss.en-US.resx (from Virtual Directory \App_GlobalResources\wss.en-US.resx)







2. AccessDenied.aspx (from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS)


Note: Please keep the Original file as a backup
















CSS:
<style type="text/css" >

BODY #s4-simple-card H1 {margin-bottom:10px; color:#5b4b3e ; font-size:2em; font-weight:normal;padding-top:3px}

.ms-sectionheader {font-family: Verdana, Arial, sans-serif; color:#595959; font-size:2em }

.ms-descriptiontext {text-align:left; font-family:Verdana, Arial, sans-serif; color:#3f3f3f;font-size:10pt}
A:link, .ms-descriptiontext A:visited, .ms-descriptiontext A:hover { color:#0072BC; font-weight:bold; text-decoration:none; }
.s4-simple-iconcont { z-index:2; background-image: url('/_layouts/images/setcredentials_32x32.png'); HEIGHT: 60px; TOP: 10px;
background-position:left center; background-repeat: no-repeat; }
.s4-simple-iconcont img {display:none;}

</style >

Monday, March 7, 2011

How to Control Hyper Link Attributes to Open In a New Window

Wondering how to control the Hyper Link control behavior! Like STYLE, OPEN , SET FOCUS & ATTRIBUTES

Current project requirement to open the Hyper link with specific browser attributes like With Scroll bar, No Menu bar, Specific Window Position, Height & Width.

Achieved with Java Script as shown below code:

string strURL = "http://rajadandu.blogspot.com/";

//Create Hyper Link
HyperLink h = (HyperLink)e.Row.FindControl("ConfHlink");

// Setting Style
h.Style["margin-left"] = "5px";

//Setting default Hyper Link Navigation to NULL
h.NavigateUrl = "javascript:void(null);";

//Hyper Link Display string
h.Text = "Opening With Controlled Hyper Link";

//Java Script with Open Window with attributes
//Then at last Set Focus
h.Attributes["onclick"] = "javascript:window.open('" + strURL + "','','scrollbars=yes,menubar=no,height=430,width=700,top=0,left=0,resizable=yes,toolbar=no,location=no,status=no'); window.focus();";

Thursday, March 3, 2011

Open PDF makes you save!!

After few Hrs of research find out that this particular setting will now open’s .PDF directly in IE; by default is “Strict” which prompts the user for file download.

Step-By-Step:
You can fix this by navigating in to central admin


Application Management >> Manage web application

Now choose your web application (select the row) which makes ribbon to be active

and you will see general settings (in enabled mode) Now choose general settings from the drop down

find he Browser File Handling section by default it's strict, change it to Permissive click ok and you are done!!

Tuesday, December 28, 2010

Remove Title Header from Webpart

Add this stylesheet elements to the page by using content editor webpart

<style type="text/css">
.ms-viewheadertr {
 DISPLAY: none
}
.ms-vhltr {
 DISPLAY: none
}
</style>

Before:





After:

Friday, December 17, 2010

People Search WebPart Small Font Fix

Here is the CSS to add by throwing the content editor web part or through attaching your own custom style sheet
.s4-search INPUT.ms-sbplain
{
border-bottom: #e3e3e3 1px solid;
border-left: #e3e3e3 1px solid;
padding-bottom: 0px;
padding-left: 3px;
width: 191px !important;
padding-right: 3px;
background: url(/_layouts/images/bgximg.png) #fff repeat-x 0px -511px;
height: 17px;
font-size: 13px;border-top: #e3e3e3 1px solid;
border-right: #e3e3e3 1px solid;
padding-top: 2px;
}
 Before



After







Note: If you just grab and implement font-size, SharePoint always try to over write with default search style sheet

Wednesday, November 24, 2010

SharePoint 2007 to 2010 Migration

1. Run the preupgradecheck
psexec \\SP2007Server -u domain\UserID -p yourPWD -s stsadm -o preupgradecheck
Note: I used psexec sysinternal tool, felt easy working from my Pc rather than RDPing to the server

2. Based on Above check we have 2 options out of 4 options

1. In-place upgrade
○ Use existing hardware – servers/farm offline during upgrade
○ Configuration and all content upgraded
○ Farm-wide settings preserved
○ Customizations available after upgrade
○ Recommended for small or non-production environments

2. Database Attach upgrade
○ New hardware
○ Upgrade multiple DBs at a time
○ Server farm settings not upgraded
○ Customizations must be transferred
○ Can consolidate multiple farms into one
○ Recommended if farm level configurations are minimal

3. Hybrid 1: Read-Only Database upgrade
○ Use Database Attach upgrade to preserve existing farm
○ Existing farm is put in read-only mode
○ Create a new farm and attach all content databases
○ Server farm settings not upgraded
○ Recommended over Database Attach

4. Hybrid 2: Detach Database upgrade
○ Use in-place upgrade for farm settings to preserve configurations
○ Detach and upgrade content databases
○ Alternatively, upgrade content databases in a temporary farm
○ Recommended if farm level configurations are significant

3. Pre Upgrade check will give you possible options for you to migrate, I choose Content Database Attach.

4. Identifying the .WSP files to be removed, Clean up your current 2007 environment before you migrate, so that you have less things to worry.

a. Used Bamboo SharePoint Analyzer http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/11/06/introducing-bamboo-sharepoint-analyzer.aspx Choose where solution is used Option. To Identify Solutions and Features that have been deployed, displayed per Web App, Site Collection or Site scope
Now they even have client version, so you can run from your local PC.

5. Downloaded the STSADM Extender for automating the deleting away the unwanted web parts
Please Install the http://stsadm.blogspot.com/2007/10/set-web-part-state.html STSADM Extended commands to strip the web parts from the pages.
 
Download from:
SharePoint 2007 STSADM Extension WSP Files (SP2 is Recommended)
MOSS Only STSADM Extensions (x86, x64)
To install for the first time run the following commands (make sure you are in the directory where you downloaded the file):

stsadm -o addsolution -filename Lapointe.SharePoint.STSADM.Commands.wsp

stsadm -o deploysolution -name Lapointe.SharePoint.STSADM.Commands.wsp -immediate -allowgacdeployment

stsadm -o execadmsvcjobs


6. Stsadm -o gl-setwebpartstate -url "http://SP2007Server/default.aspx" -title "Un wanter WP Title like custom Events" -delete -publishUse the Excel sheet to generate the script for us.
You need Primarily 2 main fields Web Page & Display Web Part You get these 2 values from Bamboo Analyzer.
Formula to get script =CONCATENATE("stsadm -o gl-setwebpartstate -url """,[@[Web Page]],""" -title """,[@[Display Web Part]], """ -delete -publish")OR
Manually Strip web parts:
Find the pages then add the ?contents=1 to go to Manage Web part Page; then remove away the web parts & checked in those are checked out by other user(s) Note: Make sure you check out the Page.

7. Taking DB Offline on 2007 Env.
a. STSADM -o deletecontentdb –url "http://SP2007Server/" -databasename "WSS_Content" -databaseserver "SP\SHAREPOINT"

b. USE master
Go
ALTER DATABASE WSS_Content SET OFFLINE WITH
ROLLBACK AFTER 60 SECONDS

c. USE [master]
GO
EXEC master.dbo.sp_detach_db @dbname = N'WSS_Content',
@keepfulltextindexfile = N'true'
GO
8. My assumption is that you already have or created a new web application and site collection
Taking DB Offline on 2010 Env. (newly created site collection)
a. STSADM -o deletecontentdb –url "http://SP2010Server/" -databasename "WSS_Content_SP2010" -databaseserver "SP\SHAREPOINT"

b. USE [master]
GO
EXEC master.dbo.sp_attach_db @dbname = N'WSS_Content',
@filename1 =N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SHAREPOINT\MSSQL\DATA\SP2007\WSS_Content.mdf'
Note: You can user SQL Manager for attaching the DB, easy too!

c. Run Powershell script
i. Test-SPContentDatabase –name WSS_Content –WebApplication http://SP2010Server

For further identifying the migration issues you may encounter when you attach.

ii. New-SPContentDatabase -Name WSS_Content -WebApplication http://SP2010Server