SharePoint Internals – Hristo Pavlov’s Blog

2 December, 2008

The file is currently checked out or locked for editing by another user

Filed under: SharePoint — Tags: , , , , — hristopavlov @ 12:52 am

This is a nasty one. If you try to rename a folder from the SharePoint UI sometimes you may get an error saying “The file is currently checked out or locked for editing by another user”. If you enable  the callstack in the Web.config the full stack trace will be something like this:

[COMException (0x81020036): The file is currently checked out or locked for editing by another user.]
   Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +0
   Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +411

[SPException: The file is currently checked out or locked for editing by another user.]
   Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +556
   Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +3032
   Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +636
   Microsoft.SharePoint.SPListItem.Update() +194
   Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +1806
   Microsoft.SharePoint.WebControls.SaveButton.SaveItem() +111
   Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +476
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +50
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3215

 It turns out that SharePoint will not allow you to rename a folder if there is a file under it which is currently checked out. The trouble is SharePoint doesn’t tell you which is the file.

To find out which is the file you can use SharePoint Designer to rename the same folder. Then the error message returned by SharePoint Designer will include the file name being checked out and the user it is checked out to.

30 April, 2008

EditForm.aspx not shown when uploading a document

Filed under: SharePoint — Tags: , , , , , — hristopavlov @ 7:56 am

I was working on this SharePoint solution where we have a whole bunch of content types, site columns and feature receivers that are adding content types to document libraries on the fly. We were doing this because the client didn’t want to use list instances in the site definitions.

So I had this very bizzare issue when in some document libraries when I was uploading a document the edit form was not shown at all. So I choose “Upload”, browse to a file, hit “OK” and instead of getting the edit form to fill in the metadata I was getting redirected to the default view of the list. The file was being uploaded successfully but the user couldn’t change the metadata during the upload. And this was happening only on some document libraries but not on others.

A quick look to the SchemaXML of some of the libraries with SharePoint Explorer revealed that the document libraries that were having the problem were missing the “Folder” content type. And unfortunately you cannot see this content type from the UI so from the UI all of the libraries were looking the same. However I could browse for the “Folder” content type and add it to my library. After doing this with the problem was resolved and the edit form was being shown once again …

Determined to find out the root of this strange behaviour I checked the code of the Upload.aspx page in the 12 hive and it releaved the code behind class used by the page:

<%@ Assembly Name=”Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>

<%@ Page Language=”C#” Inherits=”Microsoft.SharePoint.ApplicationPages.UploadPage” MasterPageFile=”~/_layouts/application.master” %>

I then started Reflector and checked what happens when the user hits “Submit”. An excerpt is shown below

protected void OnSubmit(object o, EventArgs e)

{

    if (!this.MultipleUploadMode)

    {

        …

 

        if ((!this.IsSimpleList || (spfile.CheckOutStatus != SPFile.SPCheckOutStatus.None)) && (spfile.Item != null))

        {

            SPUtility.Redirect(this.GetEditFormUrl(spfile), SPRedirectFlags.Default, this.Context);

            return;

        }

 

        …

 

    }

}

   

As the code shows the user is only redirected to the edit form if the file is checked out or if the document library is not a “Simple List”. Checking the code of the IsSimpleList property showed that “Simple Lists” are lists that have only one content type and don’t have their “Title” field marked as “ShowInEditForm” = “FALSE”

In my case when the “Folder” content type was not present the document library was having only one content type and was qualifying as a “Simple List” and as a result the edit form was not shown when uploading a document!

So what’s the moral of the story … well I guess don’t delete the “Folder” content type from your document libraries

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.