Saturday, January 10, 2009

Retrieve Worklist Item using Folio In K2 BlackPearl

Sample code how to retrieve worklist item in K2 BlackPearl using Folio in WorkflowCriteria.

using System;
using System.Collections.Generic;
using System.Text;
using SourceCode.Hosting.Client;
using SourceCode.Workflow.Client;
 
namespace K2Samples
{
    public class WorkflowAccessingSample
    {
        public void RetrieveWorklistOpenItemBasedOnFolio()
        {
            // TODO: Replace these placeholder values with values for your environment
            Worklist worklist = null;
            WorklistItem worklistitem = null;
            string _serverName = "blackpearl";
            string _user = "K2Student";
            string _domain = "DENALLIX";
            string _password = "K2pass!";

            SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString =
                new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();

            connectionString.Authenticate = true;
            connectionString.Host = "localhost";
            connectionString.Integrated = true;
            connectionString.IsPrimaryLogin = true;
            connectionString.Port = 5252;
            connectionString.UserID = _user;
            connectionString.WindowsDomain = _domain;
            connectionString.Password = _password;
            connectionString.SecurityLabelName = "K2"; //the default label
 
            // open a K2 connection
            Connection connection = new Connection();
            connection.Open(_serverName, connectionString.ToString());

            try
            {
                WorklistCriteria wc = new WorklistCriteria();
                wc.AddFilterField(WCField.ProcessFolio, WCCompare.Equal, "NR - 1");

                // open the worklist item
                worklist = connection.OpenWorklist(wc);
                if (worklist.Count == 0)
                {
                    Console.WriteLine("There has been a problem retrieving the K2 process
data. Please ensure that the account has rights to the K2
BlackPearl Workflow Item and that you are connecting to the
BlackPearl server."
);
                }
                else
                {
worklistitem = worklist[0];
                    // retrieve properties of worklist item
                    Console.WriteLine("Process Instance Name: " +
worklistitem.ProcessInstance.Name);
                    Console.WriteLine("Process Destination: " +
worklistitem.ActivityInstanceDestination.Name);
                    Console.WriteLine("Process Folio: " +
worklistitem.ProcessInstance.Folio);

                    // get the workflow actions
                    string workflowActions = "Workflow Actions: ";
                    foreach (Action action in worklistitem.Actions)
                    {
                        workflowActions += Environment.NewLine + action.Name;
                    }
                    // write actions to console
                    Console.WriteLine(workflowActions + Environment.NewLine);
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                // write error to console
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }
            finally
            {
                // close the connection
                connection.Close();
            }
        }
    }
}

Friday, January 9, 2009

Stored Procedure Paging in My Sql

Sample code of stored procedure for paging in My Sql. The input parameter are DatabaseName, WhereClause, OrderBy, PageIndex, and PageSize. The output parameter is TotalRecords.


DELIMITER $$

CREATE PROCEDURE `GetPaged`(IN DatabaseName varchar(200), IN WhereClause varchar(200),
         IN OrderBy varchar(200), IN PageIndex int, IN PageSize int, OUT TotalRecords int)

BEGIN
    DECLARE _WhereClause VARCHAR(200);
    DECLARE _OrderBy VARCHAR(200);
    DECLARE _Limit VARCHAR(20);

    SET _Limit = ' LIMIT ?,?';
    IF LENGTH(WhereClause) > 0 THEN SET _WhereClause = CONCAT(' WHERE ', WhereClause);
       ELSE SET _WhereClause = '';
    END IF;

    IF LENGTH(OrderBy) > 0 THEN SET _OrderBy = CONCAT(' ORDER BY ', OrderBy);
       ELSE SET _OrderBy = '';
    END IF;

    SET @SQLStatement = CONCAT('SELECT * FROM ',DatabaseName, _WhereClause, _OrderBy, _Limit);
    SET @Count = CONCAT('SELECT COUNT(1) INTO @TotalRecords FROM ',DatabaseName, _WhereClause);

    SET @v_PageIndex = PageIndex;
    SET @v_PageSize = PageSize;

    PREPARE SQLStatement FROM @SQLStatement;
    EXECUTE SQLStatement using @v_PageIndex,@v_PageSize;
    DROP PREPARE SQLStatement;

    PREPARE COUNTStatement FROM @Count;
    EXECUTE COUNTStatement;
    DROP PREPARE COUNTStatement;
    SET TotalRecords = @TotalRecords;
END $$

DELIMITER ;

Thursday, January 1, 2009

Get SharePoint Discussion Forum Replies Data

This is a sample code how to get all discussion replies data in sharepoint discussion forum.

1:  SPWeb web = SPContext.Current.Web;
2:  SPList listForum = web.Lists["Forum"];
3:   
4:       /* Get the Discussion Forum Data */
5:       SPQuery qry = new SPQuery();
6:       qry.Query = @"<OrderBy>
7:                         <FieldRef Name='DiscussionLastUpdated' Ascending='False' />
8:                    </OrderBy>";
9:       qry.RowLimit = 3;
10:   
11:      SPListItemCollection itemsColl = listForum.GetItems(qry);
12:   
13:      if (itemsColl.Count > 0)
14:      {
15:         foreach (SPListItem item in itemsColl)
16:         {  
17:            Response.Write("ID: " + item.ID + "<BR>");
18:            Response.Write("Name: " + item.Name + "<BR><BR>");
19:              
20:            /* Get all discussion replies */
21:            SPQuery qry2 = new SPQuery();
22:            qry2.Query = @"<OrderBy>
23:                              <FieldRef Name='DiscussionLastUpdated' Ascending='False' />
24:                           </OrderBy>";
25:   
26:            qry2.Folder = item.Folder;
27:            SPListItemCollection itemsColl2 = listForum.GetItems(qry2);
28:                
29:            if (itemsColl2.Count > 0)
30:            {
31:              foreach (SPListItem replayItem in itemsColl2)
32:              {
33:                Response.Write("Display Name: " + replayItem.DisplayName + "<BR>");
34:                Response.Write("List ID: " + replayItem.ID + "<BR>");
35:                Response.Write("List Folder ID: " +
replayItem["Parent Folder Id"].ToString() + "<BR>");
36:                Response.Write("Body: " + replayItem["Body"] + "<BR>");
37:                Response.Write("Last Replay By:" + replayItem["Author"].ToString().
Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries)[1]
+ "<BR><BR>");
38:              }
39:           }
40:           else
41:           {
42:               Response.Write("No Replay Data <BR><BR>");
43:           }
44:        }
45:     }

Disable SharePoint Single or Multiple File Upload using Javascript

Nice article how to disable single file upload in sharepoint document library or picture library using javascript.
Check it here.

If you want to disable multiple file upload you can change the javascript code :
var o = GetElementByText("ie:menuitem","Upload Document");

is changed to

var o = GetElementByText("ie:menuitem","Upload Multiple Documents");