最近做一个小项目,在部署wsp包的过程中,激活feature的时候提示错误:
Failed to instantiate file "" from module "" The specified list does not exist
在网上查了些资料,都只根据字面的意思告之这个list不存在,而我的feature receiver里已经加入了创建list的代码,经过独立测试,创建list的代码没有问题。
然后通过designer查看网站,却发现有和list同名的文件夹被创建,经过查阅资料,发现是因为在工程文件里的一个module中的Elements.xml的Url属性指向了该list,如果该list不存在,会自动生成一个与list同名的文件夹,这个文件夹是副产物,需要删掉这个文件夹。
项目需求是创建一个页面,通过elements.xml里的Url属性,和File的Type属性,将该页面可视化保存到list里,这样可以通过SharePoint list的各种feature来操作页面,比如权限控制,下载,更新,上传等等。
最后经过分步调式,发现最终原因,在feature里执行部署该module的顺序优先于运行feature receiver里的创建list的代码(详细生命周期请见下图),解决方案是:创建2个feature,第一个feature负责创建list,第二个feature负责加载module,然后在第二个feature设置Dependency,依赖于第一个feature。
SharePoint Feature 生命周期:
阶段 | 事件 | 命令 | 界面操作 |
---|---|---|---|
Add to solution store | AddSolution | ||
Deployment to server/farm | FeatureInstalled | DeploySolution | Central Admin > Operations > Solution Management |
Activation to SCOPE | FeatureActivated | or
| |
Upgrade | FeatureUpgrading (new for 2010) | UpgradeSolution | |
Deactivation from SCOPE | FeatureDeactivating | On RetractSolution if still activated when called or | |
Retraction from server/farm | FeatureUninstalling | RetractSolution | Central Admin > Operations > Solution Management |
Delete from solution store | DeleteSolution |