I wanted to do manual provisioning of files for a SharePoint project when it became clear that neither SiteDefinitions nor consistently creating new features would do the job of maintaining a product over several update cycles. However, creating files using the SharePoint object model API only allows for uploading new content files into the database, not for registering ghosted files that are rooted in the file system (12/Template or 14/Template for 2010).
I searched the web for solutions but couldn't find any really promising one. Some directly hacked the content-database using SQL, some leveraged OWSSRC-RPC calls or used the WebServices. None was supported (mine isn't either, although much less critically a hack ;).
I had to find a different method to do it and so I went to Reflector checking out what SharePoint internally would do and ended up calling the same stuff through Reflection.
This is basically it: By creating XML for a dummy module as it would appear in a feature and invoking
EnableModuleFromXml, plus some checks & co.
I thought maybe someone might find it useful. Code can be compiled for V12 and V14 object models and runs on SharePoint 2007 and 2010. This is early stage and hardly tested, so please check it out for yourself if it suits your needs.
Using the Code
There is a code file attached in which you find an Utility class in case you ever need to do these things (Note: I give absolutely no warranties for any kind of problems you might incur using it).
This will reduce the issue to a one-line call, which you have four of in the API from the utility class:
using (SPSite site = new SPSite("http://yoursharepointserver/yourwebsite"))
using (SPWeb web = site.OpenWeb())
SPList list = web.GetList(web.Url + "/Lists/SampleList");
SPDocumentLibrary doclib = web.GetList(web.Url + "/Documents") as SPDocumentLibrary;
(@"FEATURES\yourfeature\Files\HelloGhostWorld.txt", doclib, "",
web, "", "default.aspx", false,