Pages

Showing posts with label Personal Experience. Show all posts
Showing posts with label Personal Experience. Show all posts

Tuesday, January 26, 2010

How to terminate/cancel workflow from SharePoint object model

While terminating or cancelling workflow, it will delete all the tasks from the task list and it will marked task status as “Cancelled” into attached list.

Reference Link:

http://blog.brianfarnhill.com/2008/10/01/how-to-cancel-a-workflow-programmatically/

Getting access denied error while updating list items

I was getting access denied error while updating list items, I already tried to put my code into SPSecurity.RunWithElevatedPrivileges delegate, still I was getting error. Below was my actual code.

CODE:

//code line for updating list columns

Listitem.update()

List.Update()

After doing debugging and removing line by line from actual code I have figured out actual problem – the user who has contributor rights(normal user) was getting access denied error, admin users can able to update list without any problem, it’s because of LIST.UPDATE() statement, because contributor rights users don’t have permission to change anything into List settings, they can add/delete list items but they can’t able to change anything into list, after removing LIST.UPDATE() statement from my actual code, all users were able to successfully update the list items.

Enjoy!

ERROR: Workflow failed on start

I was getting below error while starting of workflow.

Workflow:System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException: The workflow failed validation.     at System.Workflow.Runtime.WorkflowDefinitionDispenser.ValidateDefinition(Activity root, Boolean isNewType, ITypeProvider typeProvider)     at System.Workflow.Runtime.WorkflowDefinitionDispenser.LoadRootActivity(Type workflowType, Boolean createDefinition, Boolean initForRuntime)     at System.Workflow.Runtime.WorkflowDefinitionDispenser.GetRootActivity(Type workflowType, Boolean createNew, Boolean initForRuntime)     at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext

I spend lots of time to find out exact resolution for workflow failed error, but I couldn’t get solution, below are some of the reference link which talks causing of issue due to migration from visual studio 2005 to 2008 workflow project, but in my case, I have created workflow into visual studio 2008 only, some articles were talking about adding some line into solution project, but that’s also not working for me.

Reference Link:

http://blog.hhebnes.no/?tag=/workflows

http://www.eggheadcafe.com/software/aspnet/31975863/sharepoint-workflow-upgra.aspx

http://geekswithblogs.net/SoftwareDoneRight/archive/2007/12/12/condition-not-found.aspx

At the last for resolving my issue, I have created new workflow file, one thing I have observed here – if I am going to change main default file name for workflow file from workflow.cs to something else, then sometime it will mess up workflow. So I would recommend not changing workflow.cs file name.

:)

SPWorkflow AlterTask didn’t work with hash table which has space into key name

While creating hash table for passing into altertask method, we need to be very careful, because it didn’t like spaces into key name, we need to put our key without spaces.

Sample Code:

taskHash["UserInputField"] = UserInputField.Text;

taskHash["UserInputField_ForHash"] = UserInputField.Text;

taskHash["Status"] = "Completed";

taskHash["Status_ForHash"] = "Completed";

SPWorkflowTask.AlterTask(taskListItem, taskHash, true);

Reference Link:

http://www.databaseforum.info/10/1131769.aspx

ERROR: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again

I was getting above error while doing altertask on SPWorkflowTask.AlterTask method.

Solution:  we need to write altertask code under SPSecurity delegate and need to write code for Allowunsafeaccess.

http://sansanwal.blogspot.com/2009/08/security-validation-for-this-page-is.html

http://support.microsoft.com/default.aspx?scid=kb;EN-US;970192

ERROR: The content type of a workflow task must be derived from the Workflow Task content type

I was getting “The content type of a workflow task must be derived from the Workflow Task content type” error while working with custom ASPX form for visual studio workflow, I have created custom content type which will be used into workflow, I have found out that my content type ID is incorrect by comparing it with some another content type ID. Visual studio activity “Createtaskwithcontenttype” must be inherited from workflow task.

Reference Links:                                

http://www.eggheadcafe.com/software/aspnet/30858987/login.aspx

http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/93679b02-bfa9-43c2-94ad-ec45191cd478

Wednesday, December 16, 2009

How to open any documents in EDIT Mode from custom ASPX page

Requirement:

We need to display documents from SharePoint Document Library into custom ASPX page and when user clicks on documents, it needs to open in “EDIT” mode, by default it’s giving user prompt to open documents in “EDIT” or “READ” only mode.

Solution:


We need to put extra JavaScript code which will open document in EDIT mode.

Reference Links:

http://ddkonline.blogspot.com/2007/07/issues-with-sharepoint-2007-checkout.html

http://www.google.com/search?q=dispex+sharepoint

http://mattknott.com/content/blog/2009/08/Stop_DispEx_Redirecting.html

http://dotnetninja.wordpress.com/2009/01/12/how-to-open-sharepoint-documents-in-edit-mode-with-internet-explorer-6-and-windows-xp-without-regfix/

ERROR: The file manifest.xml does not exist in the solution package

I was getting above error when solution package size becomes too big; I need to add below lines into cab.ddf file.

.Set CabinetFileCountThreshold=0

.Set FolderFileCountThreshold=0

.Set FolderSizeThreshold=0

.Set MaxCabinetSize=0

.Set MaxDiskFileCount=0

.Set MaxDiskSize=0

Reference Links:

http://andreasglaser.net/post/2009/03/13/SharePoint-and-the-file-manifestxml-does-not-exist-in-the-solution-package.aspx

http://ph-tom.blogspot.com/2008/04/file-manifestxml-does-not-exist-in.html

Tuesday, December 15, 2009

ERROR: Cannot override the Shared Resource Provider context obtained from the Office Server. This API can be used only when an Office Server context is either internally unavailable or defined

I was getting above error while working with BDC object model; actually I have custom code which will interact with SQL Session Provider instance and try to open SSP database.

Code

SqlSessionProvider.Instance().SetSharedResourceProviderToUse(“SSPName”);

I have found out that I need to change my custom code to work properly to remove error, I got very good reference from http://blogs.msdn.com/syedi/archive/2009/05/28/populating-the-bdc-field-of-a-splistitem-from-client-application.aspx link, which provided me BDC object model code with example.

Thank you!

ERROR: The type or namespace name 'ApplicationRegistry' does not exist in the namespace 'Microsoft.Office.Server' (are you missing an assembly reference)

I was working with BDC object model and accessing BDC application definition file from my custom ASPX page, I have included correct assembly for 'ApplicationRegistry' class but still it was giving me above error, after sometime I have realized that actually it’s looking for different assembly name to be included into page.

i.e. Microsoft.SharePoint.Portal (in microsoft.sharepoint.portal.dll).

After adding Microsoft.SharePoint.Portal assembly into page, I didn’t get any error :)

 Good Job!

SharePoint Timer Job ERROR: This job will be skipped. Failed to connect to an IPC Port: Access is denied.

I got timer job error into my virtual machine when I was running timer job by stsadm command –execadmsvcjobs

Solution:

In my case, my ‘Windows SharePoint Services Timer' service was running with normal user account, I need to changed user credentials have system account which has access to database also.

 Reference Link:

 http://ari-techno.blogspot.com/2009/08/job-failed-with-following-error-this.html

Friday, December 11, 2009

How to stop event handler recursion

I was getting errors into event log when I was trying to update list in which I have written event handler code and again that code was executed from event receiver only, so it goes in loop, sometimes my page becomes very slow.

Solution:

I need to write code which will disabled event firing before when I was trying to update something into same list and then I need to enable event firing after my code.

SAMPLE CODE:

this.DisableEventFiring();

objtem.SystemUpdate(false);

this.EnableEventFiring();

Reference Links:

 

http://www.sharepoint-tips.com/2006/10/preventing-event-handler-recursion.html

Thank you!

How to impersonate user into event receiver class or Access denied error on event receiver

Requirement:

I need to remove user permission from list item based on some specified condition; normal user don’t have rights to remove user level permission, so I need to put my business logic into RunWithElevatedPrivileges delegate into event receiver class, but I was facing some challenges after that also, normal user was getting access denied errors while breaking inheritance of list item into event receiver class.

Solution:

We need to be very careful while writing impersonation code into event receiver, because if we miss one class or object to take reference from current logged in user then code won’t work, in my case – I was taking List Item on current logged in user context, I need to be very specific for taking List Item. Key here is needs to take list item by SPListItem objItem = elevatedWeb.Lists[properties.ListId].GetItemById(properties.ListItem.ID);

 

SAMPLE CODE:

 

SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite elevatedSite = new SPSite(properties.SiteId))

                {

                    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(properties.RelativeWebUrl))

                    {

                        SPListItem objItem = elevatedWeb.Lists[properties.ListId].GetItemById(properties.ListItem.ID);

  objItem.Web.AllowUnsafeUpdates = true;

                                objItem.BreakRoleInheritance(false);

                            objLeaseItem.Web.AllowUnsafeUpdates = true;

}

                    }

                });

Reference Links:

http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/f2ccd61a-8828-4c17-8360-20d45d6b9514

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/c3d2b304-7fcc-40d2-86ce-61d9b21b03d7  

http://boris.gomiunik.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/  

Good Luck!

Saturday, September 12, 2009

Object reference not set to an instance of an object. The Solution installation failed

I was getting error "Object reference not set to an instance of an object. The Solution installation failed" while adding and deploying my solution package from STSADM command, I have looked into my event log and SharePoint log to find out the exact error, I have found out that it’s related to Admin Content SQL database.  The current user who is executing the STSADM command must have full control access to this content database.

Then I run my solution package with service account and it ran well without any problem, here we can also add current user into content database and will give full control rights to current user to executing solution package.

Good Luck!

Sunday, August 23, 2009

How to Integrate AJAX into SharePoint Site


AJAX toolkit
provides whole set of controls which we can use into SharePoint, one day I thought to use AJAX Tab control, after playing with control, I realized that apart from installing AJAX toolkit into server, I need to perform set of instructions or steps to make control working into SharePoint site.

We need to make changes into web.config file for respective web application, below are some of good links which give us information about what are the sections we need to add/edit into web.config file.

Reference Links:


http://mctalex.blogspot.com/2009/06/integrating-ajax-control-toolkit-into.html


http://www.devexpert.net/blog/pt/blog/Embedding-Ajax-Control-ToolKit-into-Shar.aspx


Here is one Codeplex tool which add all web.config entries for AJAX into SharePoint site ->

http://spajaxenabler.codeplex.com/


Take the advantage of AJAX controls!!

Sunday, July 26, 2009

Error: Invalid data has been used to update the list item. The field you are trying to update may be read only.

I was getting error “Invalid data has been used to update the list item. The field you are trying to update may be read only” when I tried to update list items with incorrect value into People and group field, I was taking value from SharePoint People picker web control and update same values into SharePoint List columns.

Actually we need to pass and assigned value into specific format to people and group data type, below link describes very good and precise information on how to get values from SharePoint people picker control and update into list columns having people data type.

http://dishashah.wordpress.com/2009/06/18/how-to-display-users-to-sharepoint-peoplepicker-and-to-get-data-from-sharepoint-peoplepicker/

Enjoy!!

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I have written web service program to fetch all list names from web application, in that case I was getting access denied error while retrieving Title of SPWEB object.

Error:


at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex) at 'SPWEB.Title' threw an exception of type 'System.UnauthorizedAccessException'

I have found that my current user don’t have access rights to access some of the sites, after giving required access rights my web service program gave me correct output without any errors.

:)

Monday, July 20, 2009

How to open InfoPath form library into new browser window

I have found many alternatives to open InfoPath form into new window, one of them would be to take InfoPath form link URL and put same URL into summary link web part or page viewer web part.

Reference Link:

http://www.infopathdev.com/forums/p/10464/37554.aspx

Error while updating SharePoint list, “The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again”

This error "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again" is very common for beginners SharePoint developer, who start developing and digging into SharePoint object model, it’s coming while updating SharePoint list, the cause of error is due to security rights, if we make web.AllowUnsafeUpdates = true and then update the SharePoint list then we won’t get above error.

Sample Code:

Web.AllowUnsafeUpdates = true;
item["Title"]=”Sample”;
item.Update();

Happy Coding !!

Error while updating list items "Cannot complete this action. Please try again."

I was getting error while updating list items; after looking into each code line by line, I have found that error comes due to incorrect syntax near CAML query, I feel that SharePoint didn’t give us good user friendly error message to debug into our code. After making correction, my code work well.

Enjoy!!