Issues with Check-in / Check-out for published documents in SharePoint document library

One of my recent findings about Check-in/Check-out, would like to share with everyone.  While trying to troubleshoot a common error with Check-in/Check-out, I got to know more about how does it works.

What is the scenario and error message, why it is interesting ?

Scenario: Launch Microsoft Word application and create a document, save it to a SharePoint document library as Test.htm.  Try to edit the same Test.htm and try to save it back to the same SharePoint Document library, you will get the following error message.

Error message: “The file cannot be saved because it is not checked out.  To make changes to this file, you must check it out.”

This error message looks pretty much common with Check-in/Check-out, we have many articles and troubleshooting tips to fix it, then what difference this article is going to make it.

The SharePoint UI will show that the document is checked-out, if you query SQL server and check the document Test.htm, it will show as checked-out.  We can’t fix this issue with common troubleshooting method until we know the root cause of the issue.

Root Cause: When you save a document file as .htm to a SharePoint document library, it creates additional resource folder and files, it won’t be visible in SharePoint UI.  When we try to edit Test.htm, the main file is getting checked-out but not all the resource folder and files.  When we try to save the Test.htm back to document library, it will try to update the resource folder and files as well, since those files are not checked out, we are getting the above error message.

here is the sample data …

Create a document library named “TestLib”
Upload a document named Test.docx
Checkout the document
Run the following query on SQL server.
             select checkoutuserid, checkoutdate, checkoutexpires,dirname, leafname from dbo.AllDocs with (nolock) where dirname = 'TestLib'
Result will look like.

NULL NULL NULL TestLib/Forms template.doc

1073741823 2009-03-28 08:56:17.000 NULL TestLib Test.docx

1073741823 2009-03-28 08:56:17.000 2009-03-28 09:06:18.000 TestLib Test.docx

NULL NULL NULL TestLib/Forms Upload.aspx

Go to document library, Edit the document Test.docx, update content, save it as “Web Page” Test.htm to the same document library.

Browse to the document library you will see 2 files, Test.docx and Test.htm.
Run the same above SQL query and compare this result.

NULL NULL NULL TestLib Forms

NULL NULL NULL TestLib/Test_files item0003.xml

NULL NULL NULL TestLib/Test_files item0001.xml

NULL NULL NULL TestLib Test_files

NULL NULL NULL TestLib/Test_files props0004.xml

NULL NULL NULL TestLib/Test_files props0002.xml

NULL NULL NULL TestLib/Test_files props0006.xml

1073741823 2009-03-28 08:57:08.000 NULL TestLib Test.htm

NULL NULL NULL TestLib/Test_files filelist.xml

NULL NULL NULL TestLib/Test_files colorschememapping.xml

NULL NULL NULL TestLib/Test_files item0005.xml

NULL NULL NULL TestLib Test.docx

NULL NULL NULL TestLib/Test_files themedata.thmx

When we try to save a document as *.htm to document library, it creates resource files, those files are not getting checked-out while check-out Test.htm. But when we try to save the document back to document library, it will try to update all the resource files, since those files are not checked-out, we get the above error message.

This is what you see in profiler trace

Proc_FetchDocForUpdate

declare @p14 tinyint
set @p14=1
exec proc_FetchDocForUpdate 'EAAB2D32-13D0-4935-896F-B038AE90D92B','937BEB2C-B921-4167-BAC0-F33A8F6B0FA5',N'TestLib/Test_files',N'item0010.xml',1073741823,-2,0,1,0,0,1,0,5242880,@p14 output
select @p14

It is trying to edit the file "item0010.xml" which is not checked out.

Workaround:

We have issues only with the file format “Web Page (*.htm; *.html)”

Instead of using .htm and .html, use the following file formats while saving webpages to document library.
“Single File Web Page (*.mht; *.mhtml)”
“WebPage, Filtered (*.htm; *.html)”

 Capture