Pages

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

Different Method of SP List Item Update

http://karinebosch.wordpress.com/walkthroughs/event-receivers-theory/

http://hristopavlov.wordpress.com/2008/05/14/uploading-a-file-event-receivers-the-file-has-been-modified-by/

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!
I had a requirement in which user can cancel / terminate workflow from custom ASPX page, I got good reference from this site http://blog.brianfarnhill.com/2008/10/01/how-to-cancel-a-workflow-programmatically/ regarding how to cancel workflow programmatically, but what I had discovered was that normal user were getting error while canceling workflow. User who has full control rights into site, they can able to cancel workflow without any errors.

ERROR:   

Value does not fall within the expected range.   at Microsoft.SharePoint.Library.SPRequestInternalClass.CancelWorkflow(String bstrUrl, String bstrListName, Guid workflowInstanceId)

Solution:

It’s because of user permission level, from out of the box workflow status page also, contributor user don’t have permission to “Terminate this workflow” functionality, so we need to put Cancel workflow logic into RunWithElevatedPrivileges delegate code. After that normal user can also cancel workflow without any errors.

SAMPLE CODE:

SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))

                    {

                        using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))

                        {

                                                            //object model code for cancelling workflow

                                   }

                    }

              });

Enjoy!