Read only field in SharePoint EditForm.aspx


Using JavaScript

First find out the tag corresponding to the input field which would like to set as read only

For this open up the editform.aspx page right click it and select view source

Say this is the tag of the input field

<input name=”TextField” type=”text” value=”Approved” maxlength=”255″ id=”4_ctl00_ctl00_TextField” title=”Status of Idea” class=”ms-long” />

Now open your editform.aspx page in SharePoint designer and add the following script to it

<script type=”text/javascript”>

function SetReadOnly()

{

// find all the elements with tag Name as INPUT

var elements=document.body.getElementsByTagName(“INPUT”);

// loop through all the elements till we find an element with type text and title as name of our field

for (index=0; index < elements.length;++index)

{

if(elements[index].type==“text”)

{

if(elements[index].title==“Status of Idea”)

{

elements[index].readOnly=true;

}

}

}

}

_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);

</script>

Or

<script type=”text/javascript”>

function SetReadOnly()

{

var elements=document.getElementById(‘4_ctl00_ctl00_TextField’);

elements.readOnly=true;

}

_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);

</script>

Or using event handler as mentioned over here

http://blogs.msdn.com/sowmyancs/archive/2008/03/25/creating-a-read-only-field-with-default-value-in-a-sharepoint-list.aspx

Or

Using CAML

http://forums.asp.net/t/1166224.aspx

And to hide button say OK button than

function SetHidden()
{
alert(‘Hi’);
var x=document.getElementsByTagName(“input”);
for (var i=0;i<x.length;i++)
{
if (x.item(i).type==”button”&&x.item(i).value==”OK”)
{
x.item(i).style.display = “none”
};
}
}
_spBodyOnLoadFunctionNames.push(“SetHidden()”);


Bye…

Collect Data from a User and Set Workflow Variable action in SharePoint Designer


The step by step instruction can be found at the below link

https://nishantrana.me/wp-content/uploads/2009/01/sharepoint.doc

Bye…

Building a simple workflow with Visual Studio 2005 in SharePoint


Create a new SharePoint Sequential Workflow project.

Drag and drop SendEmail activity just after onWorkflowActivated1 activity .

Set CorrelationToken property of SendEmail to workflowToken which is the workflow correlation token used by onWorkflowActivated1.

For MethodInvoking set the value sendEmail1_MethodInvoking and click which would generate the handler.

private void sendEmail1_MethodInvoking(object sender, EventArgs e)

{

sendEmail1.To = “myId@g.com”;

sendEmail1.From = ” myId@g.com “;

sendEmail1.CC = ” otherId@g.com “;

sendEmail1.Subject = “MySubject”;

sendEmail1.Body = ” This is test mail”;

}

}

Strong sign the assembly and install it in GAC.

Set your feature.xml as following

<Feature Id=23CB845A-7204-4d41-9873-FE50BEB78BCD

Title=Default Title

Description=This feature is a workflow that …

Version=12.0.0.0

Scope=Site

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

<ElementManifests>

<ElementManifest Location=workflow.xml />

</ElementManifests>

</Feature>

Id– Provide a new guid for uniquely identifying the feature

Title – to be displayed in the list of features deployed to the site

Description – Any description that appears beneath the Title.

Location – Leave it to default as the directory is same.

Set your workflow.xml as following

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

<Workflow

Name=My Workflow

Description=This workflow …

Id=049971BB-5BAA-4bf1-98A2-747675A18DCB

CodeBesideClass=SharePointWorkflowLibrary3.Workflow1

CodeBesideAssembly=SharePointWorkflowLibrary3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58efe34bdb2df93e

>

<Categories/>

<MetaData>

<StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>

</MetaData>

</Workflow>

</Elements>

Name – Name of the workflow.

Description – Any description about the workflow

Id – A new guid for the workflow

CodeBesideClass – Namespace.ClassName

CodeBesideAssembly – name of assembly, version , culture and publicKeyToken which we can get by right clicking the assembly in gac and selecting properties.

Remove all other entries as we are not using any forms for this workflow.

Now modify the install.bat file as mentioned in the instruction for the same.

Run install.bat

Next go to the site where the new workflow has been deployed.

Select any document library – than settings- document library settings – workflow settings – add a workflow.

We’ll see our workflow within the workflow template.

Correlation Token – A correlation token is essentially a means of uniquely identityfing each instance of a workflow, modification or task.

Bye…

Developer ramp up for MOSS (SharePoint) and Microsoft Dynamics CRM 4.0


The best place for someone starting with development in Microsoft Dynamics CRM 4.0 and MOSS development.

SharePoint Developer RampUp

Microsoft Dynamics CRM 4.0

Other Ramp Up

Bye…

SharePoint and Javascript


The following links explains how to use javascript within SharePoint

Using JavaScript to manipulate a list form field.

http://blogs.msdn.com/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

Hide a field from NewForm.aspx

http://edinkapic.blogspot.com/2007/08/hide-field-from-newformaspx.html

Using Simple JavaScript in SharePoint

http://www.sharepointkings.com/2008/06/using-simple-javascript-in-sharepoint.html

and few other links

http://sharepointsolutions.blogspot.com/2007/09/make-selected-links-in-links-list-open.html

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/941940cb-acef-434f-830f-233713773b99/

http://www.codeproject.com/KB/sharepoint/Control_validation.aspx

Bye….

Writing a simple Event Reciever or Event Handler in Sharepoint


What is 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){

// We want to attach the eventhandler against a document library

// named MyDocumentLibrary

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.

8) 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.

That’s it…