Pages

Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Monday, July 23, 2012

Iterating through every SharePoint Web Applications, Site Collections, and Sites (Webs)

Problems getting exact count of users from People and Groups: All People using SharePoint object model


There is no direct way or correct way to get all the all the users from “All People” link from SharePoint using object model. I have tried every different options from programming but none of the method gave me correct results, like web.AllUsers, web.Users, web.SiteUsers. but these properties are giving me incorrect results.


Basically I want to know and check how many users into any particular SharePoint site. After digging more into it I have found out that maybe it’s not possible to get correct count with one property, so I have changed my code to get all the users from SharePoint site like this : I am looping through all the SharePoint site groups and counting unique users from code as well as from web.Users property.


Navigation link is not appearing into SharePoint site


I was getting “Quick Launch” and “Top Link Bar” links and wondering why “Navigation” link disappear from the Look and Feel section of the site settings then I have figured out that we need to activate “SharePoint Server Publishing Infrastructure” on site collection level feature. 


After activating this site collection feature, I am able to see navigation link and other two links goes away :)


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/

Visual Studio Approval Workflow Example

http://msdn.microsoft.com/en-us/library/dd674137.aspx

http://msdn.microsoft.com/en-us/library/cc811589.aspx

How to get workflow instance for single workflow into listitem

http://nishantrana.wordpress.com/2009/02/10/using-workflow-object-model-in-sharepoint/

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!

How to attach/delete attachments from SharePoint list items

http://www.pointsharepoint.com/2008/12/list-attachments-in-webpart-solution.html

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.

:)

How to get current status of workflow from SharePoint object model

Reference Link:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowstatus.aspx

Sample Code:
//Obtain a list item
SPWeb thisWeb = SPControl.GetContextWeb(Context);
SPList issuesList = thisWeb.Lists["Customer Issues"];
SPListItem myItem = issuesList.Items[0];
//Get the workflow status value
int WorkflowStatusValue = myItem["MyWorkflow"];
string WorkflowStatusString = System.Enum.GetName
        (typeof(SPWorkflowStatus), WorkflowStatusValue);
StatusLabel.Text = "The current status of the workflow is: " +
        WorkflowStatusString;

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

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