开发者

ListInstance provisioning via CAML

开发者 https://www.devze.com 2023-04-01 02:17 出处:网络
In SharePoint 2010, is it possible to not overwrite an existing ListInstance (assuming it already exists) when provisioning a list using CAML?Or is custom code necessar开发者_开发知识库y?

In SharePoint 2010, is it possible to not overwrite an existing ListInstance (assuming it already exists) when provisioning a list using CAML? Or is custom code necessar开发者_开发知识库y?

Edit: This question was unclear on my part. I should have noted that I am deploying the list instance via a solution using the default vs2010 build/deploy process. When using this process, the list instance is being removed and re-created when I deploy. I am trying to prevent it from being re-created each time.


No, it is not possible to overwrite an existing List with the ListInstance element. You can change EnableVersioning and Hidden. You can also add items via Data/Rows/Row. But the original list remains.

From the "documentation," here is code from Microsoft.SharePoint.SPListInstanceElement:

internal override void ElementActivated(SPFeaturePropertyCollection props, SPSqlCommand sqlcmdAppendOnly, SPWebApplication webApp, SPSite site, SPWeb web, bool fForce)
{
  bool flag1 = this.FeatureDefinition.Scope == SPFeatureScope.Site;
  bool flag2 = true;
  if (this.RootWebOnly && !web.IsRootWeb)
    flag2 = false;
  if (!flag2)
    return;
  this.EnsureDataProvisioned(this.EnsureListExists(!flag1 ? web : site.RootWeb));
}

internal SPList EnsureListExists(SPWeb web)
{
  SPList spList = web.Lists.GetListByName(this.Title, false);
  if (spList == null)
  {
    // SNIP - list would be created here
  }
  bool flag = false;
  if (this.VersioningEnabled.HasValue && spList.EnableVersioning != this.VersioningEnabled.Value)
  {
    spList.EnableVersioning = this.VersioningEnabled.Value;
    flag = true;
  }
  if (this.Hidden.HasValue && spList.Hidden != this.Hidden.Value)
  {
    spList.Hidden = this.Hidden.Value;
    flag = true;
  }
  if (flag)
    spList.Update();
  return spList;
}


When deploying a solution, VS prompts the user if they want to overwrite the existing list instance. To prevent the list from being overwritten (and this prompt all together), the "Deployment Conflict Resolution" can be changed to "None". "Deployment Conflict Resolution" can be found in the properties window of the list instance element.

0

精彩评论

暂无评论...
验证码 换一张
取 消