C# 已部署的 Web 部件未显示在“Web 部件库:新 Web 部件”中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/208333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deployed Web Part not showing up in 'Web Part Gallery: New Web Parts'
提问by naspinski
I took a wsp file, and did my stsadm -o addsolutionlike usual. Then I went into central administration->solution managementand it showed up just fine. Then I deployed the web part, no problems so far.
我拿了一个 wsp 文件,像往常一样做了我的stsadm -o addsolution。然后我进入了中央管理->解决方案管理,它显示得很好。然后我部署了 Web 部件,到目前为止没有问题。
The problem is when I go to add it to the webpart gallery (Web Part Gallery: New Web Parts) usually the web part is in the list, I check the box next to it and click populate gallerybut it is not showing up in the list? Could I be missing something in my manifest.xml to cause this? I just wrote and deployed another web part this exactsame way and it went fine. Also, I wrote a dummy webpart that does nothing but print "working" and tried it with that getting the same results.
问题是当我将它添加到Web 部件库(Web 部件库:新建 Web 部件)时,通常 Web 部件在列表中,我选中它旁边的框并单击填充库,但它没有显示在列表?我是否会在 manifest.xml 中遗漏某些内容来导致这种情况?我刚刚以完全相同的方式编写并部署了另一个 Web 部件,并且运行良好。另外,我写了一个虚拟的 webpart,它只打印“工作”并尝试使用它获得相同的结果。
Any ideas?
有任何想法吗?
采纳答案by naspinski
wow... turns out that all I was missing was a 'public' declaration on my class!?!
哇...原来我所缺少的只是我班级的“公开”声明!?!
I feel like an idiot. But also, I did have to manually delete it to get it recognized. Thanks everyone!
我觉得自己像个白痴。而且,我确实必须手动删除它才能识别它。谢谢大家!
回答by TcKs
I had sometime same behaviour. Finally we wrote a cmd-tool, which run "stsadm - o addsolution" and then add to web part gallery all xml files for web parts.
我有时也有同样的行为。最后,我们编写了一个 cmd 工具,它运行“stsadm - o addsolution”,然后将 Web 部件的所有 xml 文件添加到 Web 部件库。
There is source ( little-bit edited ):
有源(稍微编辑):
string cmd_StsAdm = @"C:\Program files\Common files\Microsoft Shared\web server extensions\BIN\stsadm.exe";
string url_Site = "http://localhost";
string url_Web = "http://localhost";
if ( string.IsNullOrEmpty( url_Web ) ) { url_Web = url_Web; }
Console.WriteLine( "Deleting sharepoint solution" );
string args_DeleteSolution = string.Format( "-o deletesolution -name \"{0}\" -override", startInfo.fileNameWsp );
ShellWait( cmd_StsAdm, args_DeleteSolution );
string filePathWsp = "**** path to wsp file ****";
Console.WriteLine( "Adding sharepoint solution" );
string args_AddSolution = string.Format( "-o addsolution -filename \"{0}\"", filePathWsp );
ShellWait( cmd_StsAdm, args_AddSolution );
Console.WriteLine( "Deploy sharepoint solution" );
string args_DeploySolution = "-o deploysolution -name \"{0}\" -local -allowGacDeployment -url \"{1}\" -force";
args_DeploySolution = string.Format( args_DeploySolution, startInfo.fileNameWsp, url_Web );
ShellWait( cmd_StsAdm, args_DeploySolution );
int counter = 0;
foreach ( CWebPartVytvoreniInfo wpRslt in solutionInfo.WebParts ) {
counter++;
string msg = string.Format( "Aktivace web part {0} - {1} z {2}", wpRslt.Info.Nazev, counter, solutionInfo.WebParts.Count );
Console.WriteLine( msg );
string args_ActivateFeature = "-o activatefeature -id {0} -url {1}";
args_ActivateFeature = string.Format( args_ActivateFeature, wpRslt.Info.ID, url_Site );
ShellWait( cmd_StsAdm, args_ActivateFeature );
}
Console.WriteLine( "Connecting to sharepoint site" );
using ( Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite( url_Site ) ) {
Microsoft.SharePoint.SPList ctg_WebParts = site.GetCatalog( Microsoft.SharePoint.SPListTemplateType.WebPartCatalog );
counter = 0;
foreach ( WebPartInfo wpInfo in solutionInfo.WebParts ) {
counter++;
string dirPath = System.IO.Path.Combine( wpInfo.DirectoryPath );
string fileName = wpRslt.Info.Nazev + ".webpart";
string filePath = System.IO.Path.Combine( dirPath, fileName );
string msg = string.Format( "Uploading file '{0}' - {1} z {2}", fileName, counter, solutionInfo.WebParts.Count );
Console.WriteLine( msg );
using ( System.IO.FileStream fstrm = OtevritSoubor( filePath ) ) {
ctg_WebParts.RootFolder.Files.Add( fileName, fstrm, true );
}
}
}
回答by Alex Angas
Check that the .webpart file deployed to the wpcatalog folder of your web site. Depending on what directory was specified when provisioning the web application, you should find it in a location similar to this:
检查 .webpart 文件是否部署到您网站的 wpcatalog 文件夹。根据配置 Web 应用程序时指定的目录,您应该可以在类似于以下位置找到它:
c:\Inetpub\wwwroot\wss\VirtualDirectories\80\wpcatalog
c:\Inetpub\wwwroot\wss\VirtualDirectories\80\wpcatalog
回答by Nat
I have found that if I deployed a webpart that was borken previously I have had to manually delete it after removing the solution, before re-adding the solution
我发现如果我部署了一个以前被破坏的 webpart,我必须在删除解决方案后手动删除它,然后再重新添加解决方案
回答by naspinski
Target .NET Framework was the issue for me. I targeted .NET 3.5 and that didn't work for me. So I targeted .NET 3.0 instead, and that worked out well.
Target .NET Framework 是我的问题。我的目标是 .NET 3.5,但这对我不起作用。所以我的目标是 .NET 3.0,而且效果很好。
回答by Mariusz Ignatowicz
I've had the same problem with a Web Part I've been working on but in my case I simply forgot to add a Web Part to "Items in the Feature"box. To do this:
我一直在使用 Web 部件时遇到了同样的问题,但就我而言,我只是忘记将 Web 部件添加到“功能中的项目”框中。去做这个:
- In Solution Explorerunfold the subtree of your Feature.
- Double-click the item ending with
.feature
. - You should see a new tab with Feature's title, description and scope. Below them there are two boxes with buttons in between. From the left box select your Web Part and press the
>
button (marked on image) to add it to the Feature.
- 在解决方案资源管理器中展开功能的子树。
- 双击以 结尾的项目
.feature
。 - 您应该会看到一个包含功能标题、描述和范围的新选项卡。在它们下面有两个盒子,中间有按钮。从左侧框中选择您的 Web 部件,然后按
>
按钮(标记在图像上)将其添加到功能中。
NOTE: You can also do this by pressing the Manifest
button on the bottom and editing the Manifest file manually, if you know what you're doing.
注意:Manifest
如果您知道自己在做什么,也可以通过按下底部的按钮并手动编辑清单文件来执行此操作。
This really may help other SharePoint starters.
这确实可以帮助其他 SharePoint 初学者。