Wednesday, March 9, 2011

Get Database Tables Schema using ADO.Net Connection

Functionality for reading Database tables' schema using ADO.Net connection

public DataTable GetTables(string strConnection)
     {
         //Create connectionstring
         SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnection);
         SqlConnection con = null;
         DataTable dtTables = new DataTable();
         try
         {
             con = new SqlConnection(builder.ConnectionString);
             con.Open();
 
             //Get the Schema for the tables
             dtTables = con.GetSchema(SqlClientMetaDataCollectionNames.Tables, new string[] { null, null, null, "BASE TABLE" });
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             if (con != null)
             {
                 con.Dispose();
             }
         }
 
         return dtTables;
     }
Code can be downloaded here: Download

Wednesday, March 2, 2011

Find WorkListItems with Worklist Criteria Filter in K2 Blackpearl

While working for an utility to redirect the tasks with some custom functionality I had to search for an option to bring the WorklistItems (tasks) based on some criteria (like Folio or Title) using LIKE operator with K2 API classes WorkflowCriteria and WorkflowCriteriaFilter, but it didn’t work. Googled with some keywords and found few articles, but I could not see any simple solution from them. So did some trials on search criteria on my own finally I could figure out that if we use percentile (%) symbols with LIKE operator it works perfectly. I didn't expect this as the APIs itself should take care (as per my understanding) of this when we use LIKE operator in Criteria classes. Anyway, it is working fine for me. I thought my findings may help some folks so posted that piece of code here.


 //Create a connection string with Integrated mode
    SCConnectionStringBuilder connectionString = new SCConnectionStringBuilder();
        connectionString.Authenticate = true;
        connectionString.Host = "ServerName";
        connectionString.Integrated = true;
        connectionString.IsPrimaryLogin = true;
        connectionString.Port = 5555;

        WorkflowManagementServer workflowServer = new WorkflowManagementServer();
        try
        {
            //Create a connection
            workflowServer.CreateConnection();
            workflowServer.Connection.Open(connectionString.ToString());

            WorklistCriteriaFilter filter = new WorklistCriteriaFilter();
            // Without % symbols it won't bring any data. It is important to add
   filter.AddRegularFilter(WorklistFields.Folio, Comparison.Like, "%srinitest%");
        
WorklistItems listItems = workflowServer.GetWorklistItems(filter);
            foreach (WorklistItem item in listItems)
            {
                //Add a row  to table to show it on form
   //AddRow(item.ProcInstID.ToString(),item.Folio,item.ActivityName,     item.EventName, item.Destination, item.ProcName);

            }
        }
        catch (Exception ex)
        {
            //Handle Exception here
        }
        finally
        {
         if (workflowServer != null && workflowServer.Connection != null)
            {
                //Dispose the connection saftely
                workflowServer.Connection.Dispose();
            }
        }

You can also find the code here Download

     Hope it helps!

Thursday, February 24, 2011

Updating DataField Values within a K2 Process Instance without Admin Access

We had an issue while updating the datafield values without executing the action in the application form. If we use ProcessInstance Update method, it was obvious that we need to provide the admin rights for all the users which is not an ideal solution. So we found in the K2 Blackpearl Arcticles that we can update the Data Fields with an Action seperately created for that with in the workflow defintion. The information is described below.

 

Updating Values within a K2 Process Instance

KB Number:KB000307

Introduction

When updating values (i.e. a data field) of a process instance without completing the process in pre-0807 releases of K2 blackpearl it was possible to use the [WorkListItem].[ProcessInstance].Update() method. In K2 blackpearl 0807 the [WorkListItem].[ProcessInstance].Update() method now requires a user with process Admin rights.

The recommended way to update values of a process instance without completing it is to use the Actions["UpdateWorkItem"].Execute() method. The Action must be configured to support the updating of the work item in order to use the Execute method in the API.

Configure the Action in K2 Designer for Visual Studio

The Add Action dialogue screen contains a radio button option that enables the Action to be updated without the Worklist item being completed: Click here  to see the screen shot that shows the configuration for Save with action name UpdateWorkItem.
This radio button must be selected in order to programatically update the value within a process instance.

Update the Work Item Using the K2 API

The recommended method uses an "update" action, as opposed to firing the ProcessInstance.Update() method, so will work without Admin permissions:

SourceCode.Workflow.Client.WorklistItem wi;
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.Actions["UpdateWorkItem"].Execute();

Remember that the Action must be configured using the This action will update the work item option during the design of the process, as demonstrated in the K2 Designer for Visual Studio section above.

The following sample will now only work if it is called by a user with Admin permissions on the process:

SourceCode.Workflow.Client.WorklistItem wi;
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.ProcessInstance.Update();

 

 

 

Sunday, February 20, 2011

Add Additional Input controls to Telerik File Upload Control

We had a requirement to include additional input controls in Telerik fileupload control template. We spent more time looking into the HTML source of Telerik control on browser once it is renedered to find a way to add these controls with Javascript, but we could not find any solution for that. Later we realized that the Telerik controls provide the client script functions for its' controls, so for upload control also we found few events like OnClientAdded tha helped us to add additional inout controls like dropdown lists and lables etc. like shown in below.

Telerik FileUpload control with additional input control in it.

Below is the screen shot of Telrik file Upload control with extra input controls shown in a single line.

The code for this post is available here. Download

How to insert images into Gmail emails


I saw so many of my friends trying to find how to insert images (inline) into Gmail emails composing. So, I thought it would be helpful to post on this on my blog.

Here are the steps those will help you to figure this out.

1. After logging in to your Gmail account you can see a round icon at the top – right of your browser, and click on that, and then you can see the popup that shows Mail settings, click on that.

2. Once you click on the Mail settings it opens a setting page where you can see a lot of tabs, and click on Labs tab as shown below.
In the Labs tab search for a section called Inserting images (or click Cntrl + F and search with ‘Inserting images’), you can see a section like below, and now select Enable button, and finally click on Save Changes button to save your settings.

3. Once the changes to your settings are saved, go back to Composing email section and you can see an insert image button showing up as shown below ( make sure that the Rich formatting is enabled in your composing textbox).

Hope it helps!

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...