Welcome to the ultimate resource of SharePoint...
Sit Back and enjoy all the posts on this. If you have any, you are welcome.
Thanks
Sumeet Gandhi
MCTS: MOSS (Config, Dev)
WSS (Dev)
hpe4xviums
@ Sunday, Jun. 21, 2009 – 03:38:38 pm
Welcome to the ultimate resource of SharePoint...
Sit Back and enjoy all the posts on this. If you have any, you are welcome.
Thanks
Sumeet Gandhi
MCTS: MOSS (Config, Dev)
WSS (Dev)
hpe4xviums
@ Wednesday, Jul. 08, 2009 – 10:58:55 am
Hi,
Well i came accross a situation where i need to get hold of current item which has just been uploaded to a document library. So the way to get that item is find the last item -> find the max item ID.
This is how i did it.
steps :
1. qry.query = " write your query to sort the list in decending order by id";
2. put the results in SPItemListCollection
3. foreach(SPListItem item in collection)
{
int itemid = item.id;
break;
}
Voila ...u got the latest item aded to the doc lib / list.
Cheers !!

@ Sunday, Jul. 05, 2009 – 11:53:25 am
Thanks Bert for sharing this information, which will probably help a lot of us out there.
The original post can be found at http://blogs.pointbridge.com/Blogs/johnson_bert/Pages/Post.aspx?_ID=10 .
Here is the script :
' Extract MOSS 2007 Product ID
' Written by Bert Johnson (PointBridge)
' http://blogs.pointbridge.com/Blogs/johnson_bert/Pages/Post.aspx?_ID=10
Const HKEY_LOCAL_MACHINE = &H80000002
Set reg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
wscript.echo GetKey("SOFTWARE\Microsoft\Office\12.0\Registration\{90120000-110D-0000-0000-0000000FF1CE}", "DigitalProductId")
Public Function GetKey(path, key)
Dim chars(24), prodid
Dim productkey(14)
reg.GetBinaryValue HKEY_LOCAL_MACHINE, path, key, prodid
For ib = 52 To 66
productkey(ib - 52) = prodid(ib)
Next
'Possible characters in the Product ID:
chars(0) = Asc("B")
chars(1) = Asc("C")
chars(2) = Asc("D")
chars(3) = Asc("F")
chars(4) = Asc("G")
chars(5) = Asc("H")
chars(6) = Asc("J")
chars(7) = Asc("K")
chars(8) = Asc("M")
chars(9) = Asc("P")
chars(10) = Asc("Q")
chars(11) = Asc("R")
chars(12) = Asc("T")
chars(13) = Asc("V")
chars(14) = Asc("W")
chars(15) = Asc("X")
chars(16) = Asc("Y")
chars(17) = Asc("2")
chars(18) = Asc("3")
chars(19) = Asc("4")
chars(20) = Asc("6")
chars(21) = Asc("7")
chars(22) = Asc("8")
chars(23) = Asc("9")
For ib = 24 To 0 Step -1
n = 0
For ikb = 14 To 0 Step -1
n = n * 256 Xor productkey(ikb)
productkey(ikb) = Int(n / 24)
n = n Mod 24
Next
sCDKey = Chr(chars(n)) & sCDKey
If ib Mod 5 = 0 And ib <> 0 Then sCDKey = "-" & sCDKey
Next
GetKey = sCDKey
End Function
@ Tuesday, Jun. 30, 2009 – 12:57:17 pm
Goal: Prevent a completed task from being edited.
Tools:
Steps:
The JavaScript:
<script type="text/javascript" language="javascript">
for info: http://techtrainingnotes.blogspot.com
var x = document.getElementsByTagName("TD") // find all of the TDs
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className=="ms-vb2") //find the TDs styled for lists
{
if (x[i].innerHTML=="Completed")
{
var theTargetNode = x[i].parentNode.childNodes[1]
// The following is all one line:
theTargetNode.innerHTML = "<a class='ms-vb2' href='javascript:TaskHasBeenCompleted()'>" + theTargetNode.getElementsByTagName("TD")[0].childNodes[0].innerHTML + "</a>"
}
}
}
function TaskHasBeenCompleted()
{
alert('This task has been completed and cannot be edited.')
}
</script>
Watch-outs:
@ Monday, Jun. 29, 2009 – 06:29:32 pm
While writing an ItemAdded handler for a SharePoint list, and the list contains multi-user fields. Since the SPItem is not actually available at this point, I think I'm relegated to using the string that comes back from the SPItemEventDataCollection. That string will look something like this when user1, user2, and user3 are present:
1;#MYDOMAIN\user1;#4;#MYDOMAIN\user2;#10;#MYDOMAIN\user3
SPFieldUserValueCollection does exactly what you're looking for. Its constructor accepts an SPWeb and string of users. The SPFieldUserValue items in the collection provide a User property that returns the corresponding SPUser objects for the web.
private void ProcessUsers(SPListItem item, string fieldName)
{
string fieldValue = item[fieldName] as string;
SPFieldUserValueCollection users = new SPFieldUserValueCollection(item.Web, fieldValue);
foreach(SPFieldUserValue uv in users)
{
SPUser user = uv.User;
// Process user
}
}
@ Sunday, Jun. 28, 2009 – 04:31:36 pm
This example uses an event handler and starts a workflow every time an item is updated in a SharePoint list.
public class ProgrammaticWorkflowInitiationEventReceiver : SPItemEventReceiver
{
/// <summary>
/// Event handler for item updated event.
/// </summary>
/// <param name="properties"></param>
public override void ItemUpdated(SPItemEventProperties properties)
{
//use this method if the workflow is associated to a list
StartListWorkflow(properties);//use this method if the workflow is associated to a content type
StartContentTypeWorkflow(properties);
}/// <summary>
/// Starts a workflow associated to a list programmatically.
/// </summary>
/// <param name="properties"></param>
private void StartListWorkflow(SPItemEventProperties properties)
{
//get list item from event handler properties
SPListItem listItem = properties.ListItem;using (SPWeb web = listItem.Web)
{
using (SPSite site = web.Site)
{
//obtain an instance of SPWorkflowManager
//which will be later used to start the workflow
SPWorkflowManager manager = site.WorkflowManager;
//get item's parent list
SPList parentList = listItem.ParentList;
//get all workflows that are associated with the list
SPWorkflowAssociationCollection associationCollection =
parentList.WorkflowAssociations;
//lookup and start the worflow
LookupAndStartWorkflow(listItem, manager,
associationCollection, "MyListWorkflow");
}
}
}/// <summary>
/// Starts a workflow associated to a content type programmatically.
/// </summary>
/// <param name="properties"></param>
private void StartContentTypeWorkflow(SPItemEventProperties properties)
{
//get list item from event handler properties
SPListItem listItem = properties.ListItem;using (SPWeb web = listItem.Web)
{
using (SPSite site = web.Site)
{
//obtain an instance of SPWorkflowManager
//which will be later used to start the workflow
SPWorkflowManager manager = site.WorkflowManager;
//get item's content type
SPContentType contentType = listItem.ContentType;
//get all workflows that are associated with the content type
SPWorkflowAssociationCollection associationCollection =
contentType.WorkflowAssociations;
//lookup and start the worflow
LookupAndStartWorkflow(listItem, manager,
associationCollection, "MyContentTypeWorkflow");
}
}
}/// <summary>
/// Lookup and start the workflow.
/// </summary>
/// <param name="manager"></param>
/// <param name="associationCollection"></param>
/// <param name="workflowInstanceName"></param>
private static void LookupAndStartWorkflow(SPListItem listItem,
SPWorkflowManager manager,
SPWorkflowAssociationCollection associationCollection,
string workflowInstanceName)
{
//iterate workflow associations and lookup the workflow to be started
foreach (SPWorkflowAssociation association in associationCollection)
{
//if the workflow association matches the workflow we are looking for,
//get its association data and start the workflow
if (association.Name.ToLower().Equals(workflowInstanceName))
{
//get workflow association data
string data = association.AssociationData;//start workflow
SPWorkflow wf = manager.StartWorkflow(listItem, association, data);
}
}
}
}
Thanks Miguel !
Cheers !!!
@ Sunday, Jun. 28, 2009 – 08:20:03 am
Yesterday I passed the 70-541 Exam ( WSS Application Development ).
I was happy to clear the exam with fair marks (not too good)...
So now I have total of 3 / 4 MS SharePoint Certificates. Just one left then this chasing would be over.
Exam was quite a tricky one many questions were from web part management and development. Rest all mix up of all.
Cheers !!
@ Saturday, Jun. 27, 2009 – 09:43:35 am
| List ID | Name | In Team Site? |
| 100 | Generic List | Yes |
| 101 | Document Library | Yes |
| 102 | Survey | Yes |
| 103 | Links List | Yes |
| 104 | Announcements List | Yes |
| 105 | Contacts List | Yes |
| 106 | Events List | Yes |
| 107 | Tasks List | Yes |
| 108 | Discussion Board | Yes |
| 109 | Picture Library | Yes |
| 110 | Data Sources | No |
| 111 | Site Template Gallery | No |
| 113 | Web Part Gallery | No |
| 114 | List Template Gallery | No |
| 115 | XML Form Library | Yes |
| 119 | Wiki Page Library | Yes |
| 120 | Custom Grid for a List | Yes |
| 150 | Project Tasks | Yes |
| 200 | Meeting Series List | No |
| 201 | Meeting Agenda List | No |
| 202 | Meeting Attendees List | No |
| 204 | Meeting Decisions List | No |
| 207 | Meeting Objectives List | No |
| 210 | Meeting Text Box | No |
| 211 | Meeting Things To Bring List | No |
| 212 | Meeting Workspace Pages List | No |
| 300 | Portal Sites List | No |
| 1100 | Issue Tracking List | Yes |
| 1200 | Administrative Tasks | - |
| 2002 | Personal Document Library | No |
| 2003 | Private Document Library | No |
@ Saturday, Jun. 27, 2009 – 09:31:18 am
From time to time I hear from SharePoint users that they always have to wait for their developers if they want to have a workflow that is not available 'Out Of The Box'.
As a respond I ask them which workflow they want to use or have and apparently most of the workflows can be created in SharePoint Designer without writing one line of code.
In this article I'm going to create a 'Content Approval' lookalike workflow, named the 'Holiday Request Approval' workflow (Human Resource managers can thank me later :-)).
Before we open up SharePoint designer, we need a 'Task' list and a 'Holiday Requests' list, which is based on the 'Custom List' template. So the easiest way is to create a site based on a 'Team Site' and add a custom list.
In the 'Holiday Request' list we create some holiday related columns, such as 'start date' and 'end date'.
Now it's time to open up SharePoint designer and load the site where we can find these holiday requests:
Once the site is open and loaded, we are going to add a new Workflow by clicking on File --> New --> Workflow button:
The cool thing about creating Workflows in SharePoint Designer is, that it's nothing more than running through a wizard and that you can create pretty nice Workflows without writing a line of code.
Wizard Step 1:
In this step we need to provide a title for the Workflow, in our case it is 'Holiday Request Approval'. Next you need to specify on which list or library you want to use it and when you want to start the workflow.
We are going to start it automatically when a new item is created in the 'Holiday Requests' list:
Wizard Step 2:
When an employee adds a request for a holiday, we need to create a task for the Human Resource manager who needs to approve or reject the request.
So we need to create a kind of special form where the manager can select his choice. Because I don't want to write one line of code I'm going to let SharePoint Designer create the form.
At the end, the form will look like this:
So the action that we are going to use is the 'Collect Data From User' action:
As you can see on the screen above, you need to provide three things:
data
First click on the data link and a new wizard will pop up:
We need to collect 2 things from the human resource manager:
Click on the add button to add these two questions on the page.
First question is the status where we are going to use a choice field so that the manager can choose between Approve or Reject:
Click Finish and add another field to make it possible for the manager to add some comments:
Once you've added these two fields click on the Finish button to complete the data part of the action.
User
The next step we need to tell who the human resource manager is so a task can be assigned on his name
(because I always wanted to approve a holiday, I will play the manager for now):
Variable to collect:
What we've actually done is, we've created a task for the human resource manager (me) to approve or reject the holiday.
Because we want to use the outcome of this task we need to save the ID of the task that we've created. This is is the variable that we want to collect.
We are going to store the ID of the task in a new variable which we call HolidayRequestTaskID:
Once we've completed the first action we need to save the respond of the human resource manager. With respond I mean, what is the status and what is the comment that the manager gave.
To save these responds we need to create 2 variables and store the responds in these variables.
Find the Action 'Set Workflow variable'. If you don't find it click on 'More Actions...'.
We have to do this 2 times, once for the approval status and once for the comments status
Variable 1
First we are going to save the answer of the first question, which is the approval status, in a new variable:
Fill in the Name of the variable and the type of content you are going to store in the variable:
Click on OK, you should be having something like this:
We've created the variable now, but we didn't tell the variable what he should keep. Click in the 'fx' button which will open up a new dialog:
What do we want to collect? Well we want to collect the things that the human resource manager provided in the task that we've created earlier.
How do we know which Task that was, because there could be more than 1 task? Remember that we've saved the ID of the task in a variable, see 'Variable to collect'.
So in the Source drop down box pick 'Tasks' as the selected source. Once you've selected the task list, you have to look for the 'Holiday Request Approve Status' field which we've created earlier. In this field you find the answer of the first question.
Because there could be multiple tasks in that list you need to tell which task you would like to use. Get the task with the ID that you saved before.
this ID is saved in the 'HolidayRequestTaskID' variable which you can load by using the 'fx' button and choose for Workflow Data.
Once you've setup all the fields click OK and do the same for the comments question.
Wizard step 3
Next we are going to create a new Workflow step. You can do this by clicking on the 'Add workflow step' link on the right side of your screen.
In this step we are going to check what the manager filled in. To do so we are going to compare the answer. The condition that you need to use is the 'Compare any data source':
In the first option you are going to select the variable where you stored the answer of the first question in, which is HolidayApproved:
and in the value part you type 'Approve':
If this condition is true, you can do a lot of things:
We are going to keep it simple and send a mail to the requester of the holiday. So use the actions button to select 'Send an Email':
You want to send an email to the person who created the item. So next to the 'To' textbox, click the addressbook button. One of the users that you van pick is the 'User who created current item':
Complete the other fields in the send mail dialog box:
Once this is done, click OK.
Normally you will do an action if it is not approved.
Last step
Finish the creation of the Workflow and add a new item in your list, if everything went right you should have a new task created for the human resource manager that you've selected.
So, I've hope that I could show how you can create some more advanced workflows in SharePoint Designer.
Kevin, this was wonderful information. Many Thanks.
Cheers !!!
The content of this website belongs to a private person, blog.co.uk is not responsible for the content of this website.