我正在开发一个WebPart(它将在SharePoint环境中使用,虽然它不使用对象模型)我想要公开AJAX功能.由于环境的性质,直接向页面添加脚本管理器是不是一个选项,因此必须以编程方式添加.我试图将ScriptManager控件添加到我的webpart代码中的页面.
protected override void CreateChildControls()
{
if (ScriptManager.GetCurrent(Page) == null)
{
ScriptManager sMgr = new ScriptManager();
// Ensure the ScriptManager is the first control.
Page.Form.Controls.AddAt(0, sMgr);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,执行此代码时,我收到以下错误消息:
"在DataBind,Init,Load,PreRender或Unload阶段,无法修改控件集合."
是否有另一种方法将ScriptManager从WebPart添加到页面中,或者我是否只需将ScriptManager添加到将使用WebPart的每个页面(或母版页)?
我有一个Sharepoint项目列表:每个项目都有标题,描述和类型.我成功检索了它,我打电话给它result
.我想首先检查是否有任何项目result
以A开头然后是B然后是C等.我将为每个字母字符做同样的事情然后如果我找到一个以这个字符开头的单词我将必须显示粗体字符.
我最初使用此功能显示字符:
private string generateHeaderScripts(char currentChar)
{
string headerScriptHtml = "$(document).ready(function() {" +
"$(\"#myTable" + currentChar.ToString() + "\") " +
".tablesorter({widthFixed: true, widgets: ['zebra']})" +
".tablesorterPager({container: $(\"#pager" + currentChar.ToString() +"\")}); " +
"});";
return headerScriptHtml;
}
Run Code Online (Sandbox Code Playgroud)
如何检查单词是否以给定字符开头?
我已经定义了一个布尔属性,如下所示:
[Browsable(true), Category("Display"), DefaultValue(false),
WebPartStorage(Storage.Shared), FriendlyName("Obey Workflow"),
Description("")]
public bool ObeyWorkflow { get; set; }
Run Code Online (Sandbox Code Playgroud)
我希望它在webpart的属性工具箱中呈现为一个复选框,但它不显示.我的Web部件派生自Sharepoint WebPart基类.
我开发了一个必须部署在Sharepoint服务器上的"Web部件".我需要用户的用户名,该用户已登录Web部件中的sharepoint服务器.
我如何获得该用户名?
我在Sharepoint 2010中创建了一个Webpart,我需要将"Chrome Type"属性设置为"None"值.
我一直在寻找各种方法来强制组合框为"无",或覆盖在C#类的"Chrome类型",但我没有发现任何方式做他们.设置此属性的最佳方法是什么?
我有一个循环遍历文档库,如下例所示.
foreach (SPListItem item in DocumentLibrary)
{
}
Run Code Online (Sandbox Code Playgroud)
如何判断SPListItem
文件是文件还是文件夹?
我有一个可视化的Web部件(使用标准的Visual Stuido 2012模板从"添加新项目"表单创建)只有一个<div id="newsListDiv" runat="server"></div>
元素.我想使用以下代码以编程方式将自己的用户控件添加到它:
protected void Page_Load(object sender, EventArgs e)
{
NewsLine newsLine = Page.LoadControl(@"~/_ControlTemplates/MainTheme/NewsLine.ascx") as NewsLine;
newsListDiv.Controls.Add(newsLine);
}
Run Code Online (Sandbox Code Playgroud)
但是当我部署解决方案并将Web部件添加到页面时,它会显示一个错误页面,告诉我文件'/_ControlTemplates/MainTheme/NewsLine.ascx'不存在.但是,如果我查看文件夹"C:\ Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\MainTheme",我可以看到该文件存在于那里.我试图将信任级别设置为"完全",但得到了相同的错误.我也尝试在.ascx文件中添加用户控件,如下所示:
<%@ Register Src="~/_controltemplates/MainTheme/NewsLine.ascx" TagPrefix="uc1" TagName="NewsLine" %>
<div id="newsListDiv" runat="server">
<uc1:NewsLine runat="server" id="NewsLine" />
</div>
Run Code Online (Sandbox Code Playgroud)
这样就得到了编译错误:"当前上下文中不存在名称'InitializeControl'".我也注意到,只要我将注册或参考行(带有我的用户控件的路径)添加到我的.ascx文件,.g.cs文件就会变成空白!当我删除该行时,它会再次填满.我尝试了许多不同的路径着作,如"../_controltemplates/","/ controltemplates/15 /"等.但它们都没有任何区别.我在这里绝望,请帮忙!
我正在尝试从sharepoint列表中获取某些项目,具体取决于自定义列中的日期.
我已经建立了我与U2U CAML查询生成器,而这工作,但是当我把它放在我自己的代码在我的WebPart,它总是返回我的所有项目OD列表.
这是我的代码:
DateTime startDate = new DateTime(Int32.Parse(year), 1, 1);
DateTime endDate = new DateTime(Int32.Parse(year), 12, 31);
SPQuery q = new SPQuery();
q.Query = "<Query><Where><And><Geq><FieldRef Name='Publicate Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate) + "</Value></Geq><Leq><FieldRef Name='Publicate_x0020_Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(endDate) + "</Value></Leq></And></Where></Query>";
SPListItemCollection allItem = library.GetItems(q);
Run Code Online (Sandbox Code Playgroud) 我有一个我开发的Web部件,如果我手动安装Web部件就可以了.
但是,当我按照本网站上的说明打包Web部件作为指南时:http: //www.theartofsharepoint.com/2007/05/how-to-build-solution-pack-wsp.html
我在日志文件中收到此错误:
09/23/2008 14:13:03.67 w3wp.exe (0x1B5C) 0x1534 Windows SharePoint Services Web Parts 8l4d Monitorable Error importing WebPart. Cannot import Project Filter.
09/23/2008 14:13:03.67 w3wp.exe (0x1B5C) 0x1534 Windows SharePoint Services Web Parts 89ku High Failed to add webpart http%253A%252F%252Fuk64p12%252FPWA%252F%255Fcatalogs%252Fwp%252FProjectFilter%252Ewebpart;Project%2520Filter. Exception Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot import Project Filter. 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(...
09/23/2008 14:13:03.67* w3wp.exe (0x1B5C) 0x1534 Windows SharePoint …
Run Code Online (Sandbox Code Playgroud) 我有一个SharePoint Web部件(实际上只是一个"Hello World"应用程序),我刚刚创建并且部署它时遇到问题.我签署了.dll,创建了.dwp,并在web.config中将其注册为安全控件.我可以将它添加到Web部件库并为其添加详细信息; 但是,当我尝试将其添加到页面时,我收到以下错误:
无法显示或导入此页面上的Web部件或Web窗体控件.无法找到该类型或未注册为安全类型.
以下是我的.dwp文件:
<?xml version="1.0"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=################</Assembly>
<TypeName>MyWebParts.SimpleWebPart</TypeName>
<Title>My Simple Web Part</Title>
<Description>A simple Web Part</Description>
</WebPart>
Run Code Online (Sandbox Code Playgroud)
和我添加到web.config的条目:
<SafeControl Assembly="SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=################" Namespace="MyWebParts" TypeName="*" Safe="True" />
Run Code Online (Sandbox Code Playgroud)
我也尝试使用通配符作为命名空间,但没有帮助.我甚至尝试将web.config信任级别设置为"Full"(我不会在生产中做,但试图尝试缩小问题范围)并且仍然没有运气.有任何想法吗?谢谢.