Click here to Skip to main content
12,827,730 members (47,603 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 24 Jul 2010

How to Programmatically Create Ghosted Files in SharePoint 2007 or 2010 using the Object Model API Only

, 24 Jul 2010 Public Domain
Rate this:
Please Sign up or sign in to vote.
Provisioning of ghosted (uncustomized) files that are rooted in the File system rather than the content Database.


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:

// Example program (adjust URLs to your needs and make sure template 
// files are available in the 12/14 hive): 

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; 

	list, FileProvisionMode.OverwriteExistingIfNotCustomized);

	doclib, FileProvisionMode.OverwriteExistingIfNotCustomized);

	(@"FEATURES\yourfeature\Files\HelloGhostWorld.txt", doclib, "", 

	web, "", "default.aspx", false, 



This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionAwesome Pin
jkuter19-Jul-11 7:09
memberjkuter19-Jul-11 7:09 
GeneralThanks Pin
gojics13-Jul-11 17:47
membergojics13-Jul-11 17:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 24 Jul 2010
Article Copyright 2010 by FREVDS
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid