Search blog.co.uk

  • Sticky Welcome

    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

  • How to get the max(itemID) from CAML Query

    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 !!

  • Sites made in SharePoint.

    Hi,

    Want to see some live sites made in SharePoint.

    Here's the huge resource.

    Cheers !!

  • Recover Your SharePoint 2007 Product ID (helpful after messing up with SP2)

    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

    save that to a file named MOSS2007ProductID.vbs and run it to recover your key.  Once recovered, re-apply your Product ID through Central Admin,
    Cheers !!
  • Locking a Completed Task

    Goal: Prevent a completed task from being edited.

    Tools:

    • Content Editor Web Part (CEWP)
    • JavaScript that:
      • Finds table cells with the word “Completed”
      • Finds the parent row and then the second cell in the row
      • Replaces that cells contents with the name of the task and a hyperlink to a message

    Steps:

    • Display the task list view to modify (each view will need its own web part and JavaScript)
    • Add a Content Editor Web Part:
      • Go to Site Actions, Edit Page
      • Add a Content Editor Web Part and move it below the task web part
      • Click in the web part, click Edit, Modify Shared Web Part, and in the Appearance section change "Chrome" to "None".
    • Add the JavaScript:
      • Click the Source Editor button
      • Type or paste the JavaScript (example below)
      • Note that this example assumes that the cell with the link and dropdown list is the second cell in the row (cell 1).   i.e. “childNodes[1]”

    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:

    • Remember to add this to your rebuild / disaster recovery plan documentation!
    • Users will be able to get to the task and edit it through a direct URL to the task edit page or through any other views you have not modified.
  • Get the SPUser

    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
     
    }
    }

  • Start a Workflow Programmatically and from the Event Handlers

    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 !!!
  • Passed 70-541 WSS Application Development !!

    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 !!

  • SharePoint list template names and ID

    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
  • Create a custom workflow using SharePoint Designer

    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.

    1. screen_ListsinQuickLaunch

    In the 'Holiday Request' list we create some holiday related columns, such as 'start date' and 'end date'.

    2. screen_ColumnsInList

    Now it's time to open up SharePoint designer and load the site where we can find these holiday requests:

    3. screen_OpenSiteInDesigner

    Once the site is open and loaded, we are going to add a new Workflow by clicking on File --> New --> Workflow button:

    4. screen_NewWorkFlow

    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:

    5. wizardscreen_step1

    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:

    36. Whooow

    So the action that we are going to use is the 'Collect Data From User' action:

    6. wizardscreen_step2_CollectDataFromUser

    7. wizardscreen_step2_CollectDataFromUserLine

    As you can see on the screen above, you need to provide three things:

    1. The data that needs to be collected
    2. The user that needs to provide the data, the human resource manager
    3. A variable to collect, I'm coming back on this later ...

     

    data

    First click on the data link and a new wizard will pop up:

    8. wizardscreen_step2_datawizard1

    8. wizardscreen_step2_datawizard2

    We need to collect 2 things from the human resource manager:

    • Can the employee go on holiday or not?
    • Some extra comments

    Click on the add button to add these two questions on the page.

    10. wizardscreen_step2_datawizard3

    First question is the status where we are going to use a choice field so that the manager can choose between Approve or Reject:

    11. wizardscreen_step2_datawizard3_1

    12. wizardscreen_step2_datawizard3_11

    Click Finish and add another field to make it possible for the manager to add some comments:

    13. wizardscreen_step2_datawizard3_2

    14. wizardscreen_step2_datawizard3_22

    15. wizardscreen_step2_datawizard4

    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):

     16. wizardscreen_step2_thisuser

    17. wizardscreen_step2_thisuser_1

     

    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:

    18. wizardscreen_step2_newvariable

    19. wizardscreen_step2_newvariable_1

    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...'.

    20. wizardscreen_step2_NewAction

    21. wizardscreen_step2_SetWorkflowVariable

    22. wizardscreen_step2_SetWorkflowVariableOverview

    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:

    23. wizardscreen_step2_SetWorkflowVariable_1

    Fill in the Name of the variable and the type of content you are going to store in the variable:

    24. wizardscreen_step2_SetWorkflowVariable_2

    Click on OK, you should be having something like this:

    25. wizardscreen_step2_SetWorkflowVariable_3

    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:

    26. wizardscreen_step2_SetWorkflowVariable_4

    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.

    27. wizardscreen_step2_SetWorkflowVariable_5

    this ID is saved in the 'HolidayRequestTaskID' variable which you can load by using the 'fx' button and choose for Workflow Data.

    afterwardsadded

    Once you've setup all the fields click OK and do the same for the comments question.

    28. wizardscreen_step2_SetWorkflowVariable_6

    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.

    29. wizardscreen_step2_AddWorkflowStep

    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':

    30. wizardscreen_step3_CompareDataSource

    In the first option you are going to select the variable where you stored the answer of the first question in, which is HolidayApproved:

    31. wizardscreen_step3_CompareDataSource2

    and in the value part you type 'Approve':

    32. wizardscreen_step3_CompareDataSource3

    If this condition is true, you can do a lot of things:

    • update a field
    • add the holiday to a calendar
    • ...

    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':

    33. wizardscreen_step3_SendEmail

    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':

    34. wizardscreen_step3_SendEmail1

    Complete the other fields in the send mail dialog box:

    35. wizardscreen_step3_SendEmail2

    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.

    36. Whooow

    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 !!!

Calendar
<< < November 2009 > >>
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

Footer:

The content of this website belongs to a private person, blog.co.uk is not responsible for the content of this website.