Thursday, January 26, 2012

Cancel the LongRunningOperationJob in SharePoint 2007 when click on Cancel button

About  LongRunningOperationJob: 

              In SharePoint, Microsoft.SharePoint.Publishing.Internal provides "LongRunningOperationJob" class which prevents the timeout issue and used when long running operations(example: insert/update data in database at button submit event if its taking long time). It needs to activate the publishing feature : in SharePoint site , go to SiteActions->SiteSettings-> under "Site Collection Administration" click on "Site collection features"->Office SharePoint Server Enterprise Site Collection features.
 
Issue Faced:

              In SharePoint 2007, i am uploading excel file with large data and reading data from excel file then inserting data into DB. in this case i am using "LongRunningOperationJob" class in aspx page, successfuly its uploaded. but user wants to cancel this upload operation while uploading. i used "UserCanCancel = true;" Cancel button is enabled, but it is not cancelled the uploading process when user hit the Cancel button..how to cancel it when hit the cancel button?.

Anwser :
                i found the solution after did some analyzation,  "LongRunningOperationjob" class contains a property named "UserRequestedCancel" which can stop the uploading process using below lines.

Code:

            for (int i = 0; i <= worksheet.Cells.LastRowIndex; i++)
              {
                    if (!this.UserRequestedCancel)
                    {
                        this.StatusDescription = "Record " + (i + 1).ToString() + " is under proccess...";
                        this.UpdateStatus();
                        this.OperationsPerformed++;
                    }
                   else
                       break;
              }

by default UserRequestedCancel will be false. once clicked on Cancel button UserRequestedCancel will be true.





No comments:

Post a Comment