Wednesday, January 25, 2012

Cannot Delete Files From Document Library

The problem:

I needed to delete several files from my document library. I tried to do it using the ribbon. Alas, nothing was deleted. Fiddler brought to my attention that the request was nioved; the ULS log informed me that a new request to the AccessDenied.aspx page was created. I never saw the AccessDenied.aspx page, so the results were not clear at all.

The solution:

I looked at the log again and learned that, when you are deleting the files using the ribbon, the Web request goes to the WCF client.svc web service (http://site_root/_vti_bin/client.svc/ProcessQuery).

My next step was checking the authentication for my Web application. It turned out that for this particular web application, Anonymous Authentication was disabled. When I enabled it back, everything started working.

Lesson learned:  Disabling anonymous authentication can bring some unpredictable effects.

Tuesday, January 24, 2012

Site Templates vs. Solutions

The problem:

We migrated our farm from MOSS 2007 to SharePoint 2010. Yesterday, he called us telling us that in his new environment, his new site templates are now saved in _catalogs/solutions/Forms, rather than _catalogs/wt/Forms where he expects them to see. He manages to access the _catalogs/wt/Forms path, but finds this gallery empty.

The solution:

Remember that in SharePoint 2010, there are no STP site templates! They are now replaced with solutions (which have WSP extensions) that live in _catalogs/solutions/Forms . Two gotchas there, though:

1) On migrated sites, the _catalogs/wt/Forms path is still valid. But, it now just points to a list, not a site template gallery. The STP files that lived there in MOSS 2007 are not migrated to SharePoint 2010, though, because, I repeat, there are no STP site templates in SharePoint 2010.

2) Even though there are no STP site templates in SharePoint 2010, there are STP list templates. This can cause some confusion. So, remember, STP files are only used as list templates in SharePoint 2010, not as site templates!

Tuesday, January 17, 2012

Adding a Converted File to the Same Document Library

The problem:

Sometimes, it is desirable to convert some document to PDF (or some other format) and do it automatically, whenever the document appears in the document library.

The solution:

First of all, there is no easy way to convert a document to PDF without using a third-party product. I use Muhimbi Converter for SharePoint (http://www.muhimbi.com/).

If you want to create a converted document whenever the source document appears in the document library, you need a list item receiver. Override the ItemAdded() and ItemUpdated() methods.

You will need to add a service reference to the Muhimbi Document Converter WCF service. Then, you will need to create a document converter service client to interact with that service. For more information, read

A little problem with this example is that it reads a file from the file system, rather than from the SharePoint library. You will need to get the byte array for the source document file. A good way to do it is:

SPFile spFile = copyItem.File;
string sourceFileName = spFile.Name;
byte[] sourceFile = spFile.OpenBinary();

The Convert() method takes this byte array, the open options, and the conversion settings as parameters and returns the byte array for the new file. Now you will need to add it as a new file to SharePoint. A good way to do it is:

spFolder = (copyItem.Folder == null ? copyItem.ParentList.RootFolder : copyItem.Folder);
string newFileUrl = string.Concat(spFolder.Url, "/", Path.GetFileNameWithoutExtension(sourceFileName), ".", conversionSettings.Format);
SPFile newFile = spFolder.Files.Add(newFileUrl, convFile);
newFile.Update();