我现有的 Web 部件无法在 SharePoint 中工作
我有一个标准的 ASP.NET 2.0 网站。
它有一个网页。
我的 Company.Web.dll 中有一个 Web 部件,它显示在我网站上的 Web 部件页面上。
一切都很好!!!
我想在 SharePoint 2007 中使用相同的 Web 部件。
我在 VS2008 中有一个使用 SharePoint 1.2 扩展的“站点定义”项目。 我尝试了各种方法将外部程序集中的 Web 部件添加到我的站点定义中。 我已经能够部署 Web 部件(将其添加到 Web 部件页面的 Web 部件列表中),但我未能成功将其添加到页面。
我光荣的失败:
- 创建了一个 shell Web 部件来仅显示现有的 Web 部件,基本上只是使用我的部件作为控件。
- 创建新的Web部件时尝试修改VS2008创建的X.webpart和X.xml文件。
将 Web 部件添加到页面时,两者都会导致以下错误:
异常 Microsoft.SharePoint.WebPartPages.WebPartPageUserException: 无法导入 XXXX Web 部件。
在 Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean 清除连接)位于 Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager 经理、XmlReader 读取器、布尔值 清除连接,Uri webPartPageUri, SPWeb spWeb)位于 Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager 经理、XmlReader 读取器、布尔值 清除连接,SPWeb spWeb)位于 Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String 事件参数)
是否需要通过特殊方式将现有 Web 部件添加到站点定义中?
I have a standard ASP.NET 2.0 website.
It has a webpage page.
I have a webpart in my Company.Web.dll that I display on my webpart page on my website.
All is good!!!
I would like to use this same webpart in SharePoint 2007.
I have a "site definition" project in VS2008 using Extensions for SharePoint 1.2. I have tried various ways to add the webpart from an outside assembly to my site definition. I have been able to deploy the webpart (where it is added to the webpart list of a webpart page) but I have been unsuccessful at adding the it to a page.
My Glorious Failures:
- Created a shell webpart to just display the existing web part, basically just using my part as a control.
- Attempted to modify the X.webpart and X.xml files created by VS2008 when you create a new webpart.
Both result in the following error while adding the web part to the page:
Exception
Microsoft.SharePoint.WebPartPages.WebPartPageUserException:
Cannot import XXXX Web Part.
at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean
clearConnections) at
Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager
manager, XmlReader reader, Boolean
clearConnections, Uri webPartPageUri,
SPWeb spWeb) at
Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager
manager, XmlReader reader, Boolean
clearConnections, SPWeb spWeb) at
Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
Is there a special way I need to add my existing webpart to my site definition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这听起来像是在部署时解决 GUID 的问题,因为您可以在此 SO 中阅读 问题。
This sounds like a problem resolving the GUID at deployment time, as you can read about in this SO question.
要查找 Web 部件无法导入的详细信息,请检查 ULS 日志。 它们通常位于
%CommonProgramFiles%\Microsoft Shared\web server extensions\12\LOGS
。 当您尝试将 Web 部件添加到页面时,将在此处记录一个条目。 这应该会给你更多的细节。我的猜测是这是一个代码访问安全问题。 您的 Web 部件必须经过强签名,并且需要 SharePoint Web 应用程序的 web.config 中的 SafeControl 条目。 除了这些之外,您应该能够将其添加到全局程序集缓存中以测试它是否有效(最佳实践是编写 CAS 策略文件)。 有关详细信息,请参阅在 Windows SharePoint Services 中部署 Web 部件。
在尝试将其集成为站点定义的一部分之前,我会尝试这些步骤。 那么至少您知道 Web 部件将实际运行。
此外,VSeWSS 确实是为从一开始就使用它来开发 Web 部件而设计的。 如果您有原始源,则可以尝试使用 VSeWSS 创建新的 Web 部件,然后替换为自定义代码并更新 .webpart 和功能 XML 文件。 那么它的表现应该会好一点。 如果您尚未承诺使用 VSeWSS,请尝试 WSPBuilder,因为它不会那么痛苦。
To find the details of why the web part won't import, check the ULS logs. These are typically located at
%CommonProgramFiles%\Microsoft Shared\web server extensions\12\LOGS
. An entry will be logged here at the time you attempt to add the web part to the page. This should give you more detail.My guess is that it is a code access security issue. Your web part must be strongly signed and needs a SafeControl entry in the web.config of the SharePoint web application. Apart from these things you should be able to just add it to the Global Assembly Cache to test if it works (best practice is to write a CAS policy file). See Deploying Web Parts in Windows SharePoint Services for more details.
I would try these steps before trying to integrate it as part of a site definition. Then at least you know the web part will actually run.
Also, VSeWSS is really designed for developing your web part using it from the very start. If you have the original source, you could try creating a new web part with VSeWSS and then replace with your custom code and update the .webpart and feature XML files. Then it should behave a little better. If you haven't committed to VSeWSS, try WSPBuilder as it's less painful.
ASP.NET Web 部件和 Sharepoint Web 部件不相同。 您应该能够在 Sharepoint 中使用 ASPNET Web 部件。 请参见下表:
ASP.NET 2.0 Web 部件
基于 SharePoint 的 Web 部件
要使 Sharepoint Web 部件在标准 ASPNET 应用程序中工作,您需要在 Visual Studio 中重新创建 Web 部件(作为 ASPNET Web 部件),而无需 Sharepoint 2007 引用才能使其正常工作。
我过去使用过的一个漂亮工具是 SmartPart 值得一试:
这可以让你创建一个Visual Studio 中的 ASP.NET 用户控件(可视化),然后将其托管在 Sharepoint 中。 smartpart 充当用户控件的包装器 wepart。 可以将其视为 Sharepoint 中的页面查看器 Web 部件,只不过它不是 HTML 页面,而是 ASP.NET 用户控件。
ASP.NET webparts and Sharepoint Webparts are NOT the same. You should be able to use a ASPNET webpart within Sharepoint. See the following table:
ASP.NET 2.0 Web Part
SharePoint-based Web Part
For a Sharepoint webpart to work in a standard ASPNET application you would need to recreate your webparts in Visual Studio (as an ASPNET webpart) without the Sharepoint 2007 references for it to work correctly.
One nifty tool which I have used in the past is the SmartPart Worth checking out:
This lets you create a ASP.NET usercontrol (visually) in Visual Studio and then host this in Sharepoint. The smartpart acts as a wrapper wepart for your user control. Think of it like the page viewer webpart in Sharepoint except instead of it being HTML pages its ASP.NET UserControls.
您需要 WSS 3.0、SharePoint MOSS 或 2007 才能使用 ASP.NET 2.0 WebPart。 SharePoint 2003 或更低版本以及 WSS 2.0 或更低版本不支持 ASP.NET WebPart。
You would need WSS 3.0, SharePoint MOSS or 2007 to use ASP.NET 2.0 WebParts. SharePoint 2003 or below and WSS 2.0 or below do not support ASP.NET WebParts.