Custom Access Denied Page in SharePoint

May 30 by Mukesh Kumar

I saw too many approach for customizing Accessdenied Page or any other application page but all are tedious.

No sweating, my approach is customize your System application page give a new name for that, so that your changes will not go with future update.

After that Create HTTP Module and rewrite the request page to new customized page and the settings can be maintain in Web.Config.

:-)

Customize StyleSheet for Browser Enabled InfoPath Form

May 29 by Mukesh Kumar

Stylesheet for browser enabled Infopath is located at

~\TEMPLATE\LAYOUTS\INC\ifsmain.css

For example if you want to customize Error dialog box
Modify following css class and see the effect, and can be extended
as per requirement.

 

.errorDiv
{
 z-index:100;position:absolute;
 top:0px;
 left:0px;
 display:none;
 width:300px;padding:2px 3px;
 border:1px solid #B22828;background:#FFFED7;color:#B22828;
 font-family:Verdana;
 font-size:x-small;
 text-decoration:none;font-weight:normal;
 width:50px;
 
}

Automate InfoPath Deployment / InfoPath Form not able to upload from Central Admin

February 22 by Mukesh Kumar

I faced gruesome problem when Infopath Form was not getting uploaded
in Production Server thru Central Admin.

After spending lot of time finally started drilling  sharepoint then came to know that whenever  Infopath is getting uploaded it creates feature folder with prefix FT-Guid inside 12 hive feature foldert.

This resolved all problem. In dev machine  uploaded Prod. Infopath Form thru Central Admin then it created folder inside 12 hive feature,  copy the FT-Guid Feature folder move it to production server
Just Install and Activate it to the site and it works like charm.

Using this approach there is no post deployment work to upload InfoPath. Just preaper FT-Guid feature for InfoPath from dev environment and include this along with the deployment package  feature.

Automate Infopath Upload – Infopath form not uploaded from Central Admin

February 22 by Mukesh Kumar

I faced gruesome problem when Infopath Form was not getting uploaded
in Production Server thru Central Admin.

After spending lot of time finally started drilling  sharepoint then came to know that whenever  Infopath is getting uploaded it creates feature folder with prefix FT-Guid inside 12 hive feature foldert.

This resolved all problem. In dev machine  uploaded Prod. Infopath Form thru Central Admin then it created folder inside 12 hive feature,  copy the FT-Guid Feature folder move it to production server
Just Install and Activate it to the site and it works like charm.

Using this approach there is no post deployment work to upload InfoPath. Just preaper FT-Guid feature for InfoPath from dev environment and include this along with the deployment package  feature.

Feature Elements

February 6 by Mukesh Kumar

Feature is one of the roubust way to eliminate complexity,versioning, inconsistency.

Feature Snippet:

<Feature
  Id="ud34C3075-X5C0-CD#6-9XCF-CA6BBC7D43"

ActivateOnDefault = “TRUE” | “FALSE”

  Title="Location Services"
  Description="......"

Scope=”Web/Site/WebApplication/Farm>

  <ActivationDependencies>

<ActivationDependency

      FeatureId="al94C3075-X5C0-CD#6-9XCF-4T6BBC7DA5" />
  </ActivationDependencies>
  <ElementManifests>
    <ElementManifest
      Location="Location\LocationPart.xml"/>
    <ElementManifest
      Location="CustomerLocation\CustomerLocationList.xml"/>
    <ElementFile
      Location="test.aspx"/>
  </ElementManifests>

</Feature>

ActivateOnDefault

Optional Boolean. TRUE if the Feature is activated by default during installation or when a Web application is created; FALSE if the Feature is not activated. This attribute equals TRUE by default. The ActivateOnDefault attribute does not apply to site collection (Site) or Web site (Web) scoped Features.

In general, Farm-scoped Features become activated during installation, and when a new Web application is created, all installed Web application-scoped Features in it become activated.

Scope :

Feature one can set scope at the individual Web site level.
A site collection Feature contains items that apply to the site collection
as a whole (e.g.,content types that are shared across the site collection),
as well as items that can be activated per site.

Site Collection or Site scope include list definitions
(templates and instances), modules (file sets), and item content type behaviors
(per-item custom menu options and per-item events).

Web (Web site scope)

Control,Custom Action,Custom Action Group,Hide Custom Action,List Instance, List Template,Module,Receiver

Site (site collection)

Content Type,Content Type Binding,Control,Custom Action
Custom Action Group,Feature/Site Template Association,Field
Hide Custom Action,List Instance,Module,Workflow

WebApplication (Web application)

Control,Custom Action,Custom Action Group,Document Converter
Feature/Site Template Association,Hide Custom Action

Farm (farm)

Control,Custom Action,Custom Action Group,Feature/Site Template Association,Hide Custom Action

ActivationDependency

Features can have dependencies on other Features, and these other Features can be activated when the Feature that depends on them is activated.

Note : Windows SharePoint Services does not support a cross-scope activation dependency if the current Feature depends upon another Feature at a more restrictive scope, or if the current Feature depends on a hidden Feature. Click here

ElementManifest : Definition for a feature element

ElementFile : Support file required for the Feature this may contain

master pages, page layouts, images, style sheets etc

Click here:

Feature that provisions the instances does not remove the instances upon deactivation.

Provision a File : the Module element within a Feature or site definition. The Module element allows you to add one or more files, or file set, to a SharePoint Web site or document library.

Type="GhostableInLibrary"

This setting tells Windows SharePoint Services to create a list item to go with your file when it is added to the library

Type="Ghostable"

Provisioning a file outside a document library.

Install Solution

December 28 by Mukesh Kumar

Install Solution

The deployment of a WSS solution to a front-end Web server or an application server is performed in two phases

1. Add wsp to Solution Store
The solution store is part of the configuration database and stores the
various .wsp files
2. Deploy Solution
Solution can be deployed to one or more WSS Web Server/Application Server

stsadm -o addsolution -filename MKSTest.wsp
stsadm.exe -o execadmsvcjobs

stsadm -o deploysolution -name MKSTest.wsp -url http://xyz.com
Note : Targeting one site collection
stsadm -o deploysolution -name MKSTest.wsp -immediate -allcontenturls -allowGacDeployment -allowCasPolicies
Note: Push  solution to every site collection available within the server farm

stsadm.exe -o execadmsvcjobs
stsadm -o installfeature -name MKSTestFeature  -force
stsadm -o activatefeature -name MKSTestFeature  -force -url http://localhost

Uninstall Solution

stsadm -o uninstallfeature -name MKSTestFeature  -force
stsadm -o deactivatefeature -name MKSTestFeature  -force -url http://localhost
stsadm -o retractsolution -name MKSTest.wsp -immediate -allcontenturls
stsadm.exe -o execadmsvcjobs
stsadm -o deletesolution -name MKSTest.wsp -override

MOSS 2007 Timer Jobs

December 28 by Mukesh Kumar

SharePoint Timer service is similar to Windows Task or Windows Services.
Time job inherits from

Microsoft.SharePoint.Administration.SPJobDefinition

using System;
using System.Net;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace MKS.Demo {
  public class TestTimerJobs : SPJobDefinition {

    public TestTimerJobs() : base() { }

    public TestTimerJobs(SPWebApplication webApp)
      : base(Globals.JobName, webApp, null, SPJobLockType.ContentDatabase) {
      this.Title = Globals.JobName;
    }

public TestTimerJobs(string TimerName , SPWebApplication webApp)
      : base(TimerName , webApp, null, SPJobLockType.ContentDatabase) {
      this.Title = TimerName ;
    }

  }
}

There are three different types of locking,

  • SPJobLockType.ContentDatabase Locks the content database associated with the job.
  • SPJobLockType.Job Locks the job to prevent multiple instances of the job from running on a single server.
  • SPJobLockType.None No locking.

Override the Execute virtual method defined in the SPJobDefinition.

public override void Execute (Guid targetInstanceId)
{
//Write your custom Logic here.
}

Compile the DLL and place it into GAC.

Deploymet


    // Get the object of TestTimerJobs what is deployed in GAC
    TestTimerJobs taskLoggerJob = new TestTimerJobs("TEST TIMER JOB", site.WebApplication);
    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 5;
    TestTimerJobs.Schedule = schedule;
    //update the job
   TestTimerJobs.Update();
BeginSecond and EndSecond specify that timer job can start
randomly in between.

Interval is a 32-bit integer that specifies the interval in minutes. The default value is 5.

Where to apply Workflow in Sharepoint

December 25 by Mukesh Kumar

1. At  List or Document Library

2. Content Type defined at List

3.Content Type defined at Site Scope
Your Site > Site Settings > Site Content Type Gallery > Site Content Type

Workflow Status

November 3 by Mukesh Kumar

Here is my finding for workflow status.

Not Started                       –> 0
Failed on Start                  –>  1
In Progress                       –>  2
Error Occurred                  –>  3
Canceled                           –>  4
Completed                        –>  5
Failed on Start (retrying)   –>  6
Error Occurred (retrying)   –>  7
Canceled                          –> 15
Approved                         –>  16
Rejected                           –> 17

Find User from LookUp Field

October 30 by Mukesh Kumar

 This code snippet is how to get user from the Lookup field here I am
leaving upto SPUser object.

 

objItem is List Item which has user/group LookUp Field

SPFieldLookupValue UserLookUPValue = new SPFieldLookupValue(objItem[“YourLookUPFieldName”].ToString());

 if (((SPFieldUserValueCollection)objItem[[“YOURLOOKUPFIELDNAME”]).Count > 0)

 {

     while (intUserCount < ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”]).Count)

     {

         if (((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].User != null)

         {

             //If field contain user name

             SPUser objUser = ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].User;

            

                  //Here you can write your Business Logic 

 

         }

         else

         {

             //If field contain group name

             string strGroupName = ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].LookupValue;

             try

             {

                 SPGroup objGroup = objSPWeb.SiteGroups[strGroupName];

                 if (objGroup.Users.Count > 0)

                 {

                     SPUserCollection objUsers = objGroup.Users;

                     foreach (SPUser objuser in objUsers)

                     {

                  //Here you can write your Business Logic 

                     }

                 }

             }

             catch(Exception Ex)

             {

             }

         }

         intUserCount++;

     }

 }

 

Happy coding  :-)