以编程方式判断已部署的 Web 部件是 MOSS 附带的本机部件还是定制开发的部件?
我有一个 SharePoint 2007 MOSS 实例,并且正在执行一项事实调查任务。有多个开发人员,开发多个 Web 部件并部署它们(使用 VS2005/2008 SharePoint 扩展)。
我想也许我可以查看网站中“Web 部件库”列表中的字段,并按“修改者”进行查找,但不知何故,开发人员的名字似乎出现在某些开箱即用的 Web 部件上,而我知道是定制开发的,他们说“系统帐户” - 所以查看此列表中的该字段是不行的。
我当时想也许我可以查看每个 Web 部件分配到的“组”,但看起来它们被任意地分配到许多不同的组,不一致 - 所以使用该信息是不行的。
这是我的代码,用于循环并获取所有 Web 部件的名称。我可以在 Web 部件列表项上访问任何属性来告诉我它是否是自定义开发的 Web 部件?有什么方法可以区分自定义 Web 部件和开箱即用的 Web 部件吗?还有其他方法可以做到这一点吗?
#region Misc Site Collection Methods
public static List<string> GetAllWebParts(string connectedSPInstanceUrl)
{
List<string> lstWebParts = new List<string>();
try
{
using (SPSite site = new SPSite(connectedSPInstanceUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Web Part Gallery"];
foreach (SPListItem item in list.Items)
{
lstWebParts.Add(item.Name);
}
}
}
}
catch (Exception ex)
{
lstWebParts.Add("Error");
lstWebParts.Add("Message: " + ex.Message);
lstWebParts.Add("Inner Exception: " + ex.InnerException.ToString());
lstWebParts.Add("Stack Trace: " + ex.StackTrace);
}
return lstWebParts;
}
#endregion
I have a SharePoint 2007 MOSS instance, and I'm on a fact-finding mission. There have been multiple developers, developing multiple webparts and deploying them (using VS2005/2008 SharePoint Extensions).
I thought maybe I could look at the fields in the "Web Part Gallery" list in my site, and look by "Modified by", but it looks like a developer's name is on some of the out-of-the-box webparts somehow, and on ones I know are custom developed, they say "System Account" - so looking at that field in this list is a no go.
I thought then maybe I could look at the "Group" to which each webpart was assigned but it looks like they were arbitrarily assigned to many different groups inconsistently - so using that piece of information is a no go.
Here is my code I have for just looping through and getting the names of all the webparts. Is there any property I can access on the list items of webparts that would tell me whether it's a custom developed webpart? Any way to distinguish the custom webparts from the out-of-the-box ones? Is there another way to do this?
#region Misc Site Collection Methods
public static List<string> GetAllWebParts(string connectedSPInstanceUrl)
{
List<string> lstWebParts = new List<string>();
try
{
using (SPSite site = new SPSite(connectedSPInstanceUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Web Part Gallery"];
foreach (SPListItem item in list.Items)
{
lstWebParts.Add(item.Name);
}
}
}
}
catch (Exception ex)
{
lstWebParts.Add("Error");
lstWebParts.Add("Message: " + ex.Message);
lstWebParts.Add("Inner Exception: " + ex.InnerException.ToString());
lstWebParts.Add("Stack Trace: " + ex.StackTrace);
}
return lstWebParts;
}
#endregion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过导出 Web 部件?单击 Web 部件右上角的箭头,然后单击“导出”。它将导出为 XML 文件。查找元数据标签。例如:
type 属性将为您提供程序集信息。如果它是自定义 Web 部件,则程序集名称大部分不应是 Microsoft.Sharepoint
Have you tried exporting the webparts? Click on the arrow on the top right of the webpart and click on export. It will be exported as an XML file. Look for the metadata tag. e.g.:
The type attribute will give you the assembly information. If it is a custom webpart, the assembly name should mostly be something other than Microsoft.Sharepoint