I have come across an issue which occurs when provisioning a new Document Library and adding content to it via features.
The following issue won't happen as long as there is an Activation Dependency set for the content feature.
The scenario: I have 2 features, the first provisions a basic Document Library on my site.
Document Library Feature.xml:
The activation receiver:
using (SPWeb site = (SPWeb)properties.Feature.Parent)
{
Guid libraryID = site.Lists.Add("MyNewLibrary", "A New Document Library", site.ListTemplates["Document Library"]);
//SPList newLibrary = site.Lists[libraryID];
//newLibrary.OnQuickLaunch = true;
//newLibrary.BreakRoleInheritance(false);
//newLibrary.Update();
site.Update();
}
Content Feature.xml:
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Hidden="False"
Id="A63C95A3-616A-4d4c-8B9B-6A9D9AF2A2E1"
Title="My New Content Test"
Description="Adds some base content to MyNewLibrary"
Scope="Web">
<ElementManifests>
<ElementManifest Location="manifest.xml"/>
</ElementManifests>
</Feature>
Manifest.xml:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MyNewLibrary" Url="MyNewLibrary" List="101" Path="MyNewLibrary">
<File Url="sample.txt" Type="GhostableInLibrary" />
<File Url="TextFile1.txt" Type="GhostableInLibrary" />
<File Url="TextFile2.txt" Type="GhostableInLibrary" />
<File Url="TextFile3.txt" Type="GhostableInLibrary" />
<File Url="TextFile4.txt" Type="GhostableInLibrary" />
</Module>
</Elements>
When the Content feature is activated before the document library has been created I receive the following error message from SharePoint:
Failed to instantiate file "sample.txt" from module "MyNewLibrary": The specified list does not exist. at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrFeatureDirectory, String bstrUrl, String bstrXML)
at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrFeatureDirectory, String bstrUrl, String bstrXML)
I then return to the feature management screen and activate the document library. The activation happens without any errors being generated, but the url now has a 1 appended to it. So instead of being /MyNewLibrary as would be expected, the url is /MyNewLibrary1.
The only way I have found to correct this after it occurs is to delete the site and recreate it, then activate the features in the proper order.
I am wondering if any one else has come across this issue and can shed light on where this mysterious '1' comes from?
Thanks. Scott