June 30, 2010

Single Sign on between Sharepoint and ASP.Net Applications

All Applications to be hosted in one IIS and shud be set to windows authentication in web.config files.
Otherwise..some Kerberos Delegation...Networking and stuff.

http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/f38b4ea1-ab7e-4d55-b64f-01d6db8b02ab

June 29, 2010

Custom timer job in SharePoint

When we want to run a task (like sending emails or deleting the list items etc. . . ) in Daily basis or in Hourly basis then we can use a Timer job to this task .To see the timer job you can move to the Central Administrations then click on the operations tab, then in the Global Configuration section you can see the Timer job status and timer job definition. In timer job definition you can get the details of the timer job i.e. the title , the web application to which it is attached and the schedule type i.e. Daily, Weekly or hourly basis. To get the status of the timer job go to the timer job status, here you can view status.
Steps To create a custom timer job:

1. We need to create a class that inherits the SPJobDefinition Class. Then we need add the constructor s and the Execute () method.

namespace TestTimerJob {

public class CustomTimerJob : SPJobDefinition{

public CustomTimerJob (): base(){

}

/// <summary>

/// Initializes a new instance of the TaskJob class.

/// </summary>

/// <param name="jobName">
Name of the job.</param>

/// <param name="service">
The service.</param>

/// <param name="server">
The server.</param>

/// <param name="targetType">
Type of the target.</param>

public CustomTimerJob (string jobName, SPService service, SPServer server, SPJobLockType targetType)

: base (jobName, service, server, targetType) {

}

/// <summary>

/// Initializes a new instance of the TaskJob class.

/// </summary>

/// <param name="jobName">
Name of the job.</param>

/// <param name="webApplication">
The web application.</param>

public CustomTimerJob(string jobName, SPWebApplication webApplication)

: base (jobName, webApplication, null, SPJobLockType.ContentDatabase) {

this.Title = "Test Timer Job";

}

/// <summary>

/// Executes the specified content db id.

/// </summary>

/// <param name="contentDbId">
The content db id.</param>

public override void Execute (Guid contentDbId)

{

//Do the Operation which u want to perform

}

}

}




2. As we are going to deploy the timer job as a feature so we need to create another class which will implement the SPFeatureReceiver class. This class contains the event handlers. Here we can define the task which we are going to do when a feature will be installed, activated, deactivated and uninstalled.

namespace TestTimerJob {

class TaskJobInstaller:SPFeatureReceiver {

/// <summary>

/// Occurs after a Feature is installed.

/// </summary>

/// <param name="properties">
An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>

public override void FeatureInstalled (SPFeatureReceiverProperties properties) {

}

/// <summary>

/// Occurs when a Feature is uninstalled.

/// </summary>

/// <param name="properties">
An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>

public override void FeatureUninstalling (SPFeatureReceiverProperties properties) {

}

/// <summary>

/// Occurs after a Feature is activated.

/// </summary>

/// <param name="properties">
An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

// register the the current web

SPSite site = properties.Feature.Parent as SPSite;

// make sure the job isn't already registered

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)

{

if (job.Name == "Test Timer Job")

job.Delete();

}

// install the job

TaskJob taskJob = new TaskJob("Test Timer Job", site.WebApplication);

//To perform the task on daily basis

SPDailySchedule schedule = new SPDailySchedule();

schedule.BeginHour = 2;

schedule.BeginMinute = 10;

schedule.BeginSecond = 0;

schedule.EndHour = 2;

schedule.EndMinute = 20;

schedule.EndSecond = 0;

taskJob.Schedule = schedule;

taskJob.Update();

}

/// <summary>

/// Occurs when a Feature is deactivated.

/// </summary>

/// <param name="properties">
An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>

public override void FeatureDeactivating (SPFeatureReceiverProperties properties) {

SPSite site = properties.Feature.Parent as SPSite;

// delete the job

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) {

if (job.Name == "Test Timer Job")

job.Delete();

}

}

}

}

3. Create a feature.xml file to deploy the feature.

<?xml version="1.0" encoding="utf-8" ?>

<feature xmlns="http://schemas.microsoft.com/sharepoint/"

Id="DA0DAC0D-B1C3-4832-91ED-A20DEDC16BD4"

Title="Test Timer job"

Description="Performs the scheduled SHP tasks"

Scope="Site"

Hidden="FALSE"

Version="1.0.0.0"

ReceiverAssembly="TestTimerJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=293e555b2fe2e92a"

ReceiverClass="TestTimerJob.TaskJobInstalle">

</Feature>

4, Create a folder inside. C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ and place this file inside the folder.

Now you can install the feature using the STSADM command .After installing the feature when you activate this feature on a SharePoint site then you will be able to see the Timer job in the Timer job definition inside the central administrator.

stsadm -o installfeature -filename folder\feature.xml -force
stsadm -o activatefeature -filename folder\feature.xml -url http://...
stsadm -o deactivatefeature -filename folder\feature.xml -url http://...

SharePoint Event Handlers

Event handling ?

The ability to catch certain user actions in code and respond programmmatically. These are the classes which we can inherit and write event handlers or receivers against them.

SPItemEventReceiver

SPListEventReceiver

SPWebEventReceiver

Which user actions you can catch?

ItemFileMove,IFMoving, ItemUpdated,ItemUpdating, ItemCheckedIn/Out, ItemCheckingIn/ItemChecingOut, ItemAdded,IAdding, ItemAttachementAdded/Adding, ItemDeleted/Deleting.

What is template id for customlist, document library, survey?

100 Custom List 101 Document Library 102 Survey 103 Links List 104 Announcements 105 Contacts

106 Events List 107 Tasks List 108 Discussion Board 109 Picture Library

Explain the steps for creating event handlers?

1) Create a class library project.

2) Add reference to Microsoft.Sharepoint.dll

3) Inherit the class SPItemEventReceiver

4) Override the method against which you want to attach the event handler.

e.g. for itemdeleting

namespace MyEventHandler{

public class ItemDeletingHandler : SPItemEventReceiver{

public override void ItemDeleting(SPItemEventProperties properties){

if(properties.ListTitle == “MyDocumentLibrary”){

// only the admin user has right to delete the uploaded document

if (!properties.UserLoginName.Contains(“domainnameadminUserName”)){

properties.ErrorMessage = “You don’t have sufficient privelege to delete on list “+properties.ListTitle;

properties.Cancel = true;}}}}}

5) Sign the assembly and put it in GAC i.e. c:windowsassembly

6) Create a new folder with the same name as your eventhandler at the following path

c:program filescommon filesmicrosoft sharedweb server extension12templateFeatures folder

7) Create two files feature.xml and elements.xml at the newly created folder.

Take feature.xml file of announcement and make the necessary changes to it.

<?xml version=“1.0“ encoding=“utf-8“?>

<Feature Id=“C50FF499-B52A-471f-A9FB-36A49E2FA49F“

Title=“MyEventHandler“

Description=“For restricting delete of a list“

Scope=“Web“

xmlns=“http://schemas.microsoft.com/sharepoint/“>

<ElementManifests>

<ElementManifest Location=“Elements.xml“/>

</ElementManifests>

</Feature>

9) Within elements.xml specify

<?xml version=“1.0“ encoding=“utf-8“?>

<Elements xmlns=“http://schemas.microsoft.com/sharepoint/“>

<Receivers ListTemplateId=“101“>

<Receiver>

<Name>MyEventHandler</Name>

<Type>ItemDeleting</Type>

<SequenceNumber>20000</SequenceNumber>

<Assembly>

MyEventHandler, Version=1.0.0.0,

culture=neutral, PublicKeyToken=e185cb2eba5d0774

</Assembly>

<Class>MyEventHandler.ItemDeletingHandler</Class>

<Data></Data>

<Filter></Filter>

</Receiver>

</Receivers>

</Elements>

Get the values for assembly tag by right clicking the assembly and selecting properties within the GAC.

If we have multiple eventhandler attached to a same event we can specify which handler should be executed first through SequenceNumber tag. It’s value should start from 20000

10) Now install the feature

stsadm.exe -o installfeature -filename MyEventHandlerfeature\Feature.xml

11) Activate the feature

stsadm -o activatefeature -filename MyEventHandlerfeature\Feature.xml -URL http://localhost.

June 28, 2010

Hide Port Numbers in Sharepoint Applications (or) create all applications on one port..i.e on Port 80

1. While Creating the application, give the same port number but different host header for each application.
2. Add entry in DNS for that Host Header with the IP Address.
3. If DNS is not available, add entry in C:\Windows\System32\drivers\etc\HOSTS file with the host header and the system ip address.
Restart the IIS and Recycle the Application Pool.
Note: Site opens only in the computer where u enter the entry in HOSTS File.
4. For already created applications with different ports, go to edit bindings property of the website in IIS and change the port back to 80 and add a Host header and do the same above steps for resolving.
5. Might need to add in Alternate access mappings also in case we need to find search results.

Note: Application might be asking the credentials in a loop trying to authenticate, Windows Error..Below is the fix.

Follow these steps: Disabling the LoopBackCheck
1. Click Start, click Run, type regedit, and then click OK.
2. In Registry Editor, locate and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
3. Right-click Lsa, point to New, and then click DWORD Value.
4. Type DisableLoopbackCheck, and then press ENTER.
5. Right-click DisableLoopbackCheck, and then click Modify.
6. In the Value data box, type 1, and then click OK.
7. Quit Registry Editor, and then restart your computer

June 14, 2010

Central Administration - 403 Error - File Not Found - Access Denied - SharePoint 2010

Here is the **ucking Scenario,

1. Windows 2008 Server R2 [Front-End]
2. Windows 2008 Server R2 [Database server]
3. Installed Sharepoint Server 2010, Ran Sharepoint products and configuration wizard and everything is fine as it directs.
4. Insatlled all pre-rwq's on databse Server too.
5. Happies
6. Wanted to implement Search, cannot able to create a Search Service Application.
7. Online help - Ran Sharepoint products and Configuaration Wizard again.
8. All Sites Works, Central Admin gives 403 Error, file Not found..etc.

Resolution:

0. IISRESET, Rrefesh Application Pool, etc ....mostly doesn't work..then
1. Install the updates on Frond-End Server. There must be
Service Pack 1 for SQL Server Business Intelligence Development Studio 2008 (64-bit) (KB968369)......which was my Villian.
2. Install all updates on Database and FronEnd servers.
3. Restart the Servers.
4. Wait couple of minutes before opening Central Admin.
5. Aloha, mine was solved and if it is different from the above issue please post the resolution online...coz i searched for this like 2 days and no help online...So, help and get helped my friends.

Note: Sometimes it's nothing wrong technically, if you access the url like
http://FQDNofServer:Port/Default.aspx it works instead of just
http://FQDNofServer:Port

Help:
1. Stsadm -o deleteconfigurationobject -id Guid [removes a Service Application by id]
2. Psconfig.exe -cmd services -install [Installs Sharepoint products & Services]
3. stsadm -o spsearch -action stop|start

SonarQube with Jenkins Setup using Docker Images

https://funnelgarden.com/sonarqube-jenkins-docker/  https://medium.com/@hakdogan/an-end-to-end-tutorial-to-continuous-integration-and-con...