当我搜索有关使用代码(C#)创建内容类型的文档时,我总是找到使用SPFieldLink链接到站点的现有字段并通过以下方式添加此示例的示例
contentType.FieldLinks.Add()
Run Code Online (Sandbox Code Playgroud)
但是还有一种直接添加字段的方法.是否有一个很好的理由我不应该简单地添加字段
contentType.Fields.Add(SpField())
Run Code Online (Sandbox Code Playgroud)
?!?
提前致谢
我有一个自定义列表,可以包含CustomContentType.这是我创建一个新项目的方式:
//Create root folder
SPListItem rootItem = navigation.Items.Add();
SPContentType folderType = navigation.ContentTypes["ListLevel"];
rootItem[SPBuiltInFieldId.Title] = "root";
rootItem["ContentTypeId"] = folderType.Id;
rootItem.Update();
Run Code Online (Sandbox Code Playgroud)
问题是,当我看到我的列表后,我看到:
当我通过webbrowser转到列表并手动创建内容类型时,一切都很好.(这意味着标题是"根"而不是ID).
问题:
我有这样的标记(只有重要的行):
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RTDeluxe.ascx.cs"
Inherits="MainSolution.CONTROLTEMPLATES.Kunde.RTDeluxe" %>
<ul id="linkUl" class="teaserLinksUL" runat="server"/>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
namespace MainSolution.CONTROLTEMPLATES.Kunde
public partial class RTDeluxe : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
linkUl.InnerHtml = string.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以访问ul
代码隐藏的内部并且不会出现编译错误.但是,当我调试代码时,我得到一个NullReferenceException
因为linkUl
是NULL.
首先,我认为名称空间是原因.但是,经过几次尝试,我确信它们是正确的.在FileLocation
似乎是正确的,并且controltemplates
我的IIS的文件夹中有与它相应的ascx文件"孔德"文件夹中.
我有其他.ascx文件具有相同的结构 - >他们的工作就像一个魅力.
问题:
这种行为的名称空间还有其他原因吗?你有任何我可以看到的提示吗?
编辑:
RTDeluxe.ascx.designer.cs文件存在,生成的linkUl
如下所示:
protected global::System.Web.UI.HtmlControls.HtmlGenericControl linkUl;
Run Code Online (Sandbox Code Playgroud)
编辑2:
好的,我会尽力回答你的所有问题.感谢您的时间和反馈!
Name
在linkul-definition中添加了一个属性 - >没有更改.FindControl …
我有一个包含文件夹和项目的列表.文件夹是基于文件夹的特定内容类型,但具有属性.
文件夹可以包含子文件夹和子项.子文件夹可以包含子子文件夹等.我已经设法使用这种方式获取所有项目和文件夹:
void TraverseList(SPList list)
{
Trace.WriteLine("Traversing list: " + list.Title);
Trace.WriteLine("Base type: " + list.BaseType.ToString());
TraverseListFolder(list.RootFolder);
}
void TraverseListFolder(SPFolder folder)
{
SPQuery qry = new SPQuery();
qry.Folder = folder;
Trace.WriteLine("Foldername: " + folder.Name);
SPWeb web = null;
try
{
web = folder.ParentWeb;
SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);
foreach (SPListItem subitem in ic)
{
SPFieldLookupValue temp = new SPFieldLookupValue(subitem["TargetPage"].ToString());
Trace.WriteLine("TargetPage: " + temp);
Trace.WriteLine("ItemName: " + subitem.Name);
if (subitem.Folder != null)
{
TraverseListFolder(subitem.Folder);
}
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message); …
Run Code Online (Sandbox Code Playgroud) 我有一个带有n个孩子的CustomObject.这些子项是CustomObjects列表.像这样的东西:
public class CustomObject
{
public List<CustomObject> Children = new List<CustomObject>();
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是从单个CustomObject实例中获得所有n个孩子及其子女和子女等的最高效的方法.有没有比循环遍历所有veigns更好的方法,直到我到达结尾(null)?
(C#,.NET 3.5)
为了更清楚,我将做一个示例结构:
//root object
CustomObject.Children ->
CustomObject.Children ->
CustomObject
CustomObject
CustomObject.Children ->
CustomObject.Children ->
CustomObject
CustomObject
CustomObject
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我需要在根对象下面获取所有自定义对象.
我有一个ASP DropDown,声明如下:
<asp:DropDownList ID="DropDown1"
runat="server"
OnSelectedIndexChanged="DropDown1_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
Run Code Online (Sandbox Code Playgroud)
数据以这种方式填充:
DropDown1.DataSource = source;
DropDown1.DataTextField = "Key";
DropDown1.DataValueField = "Value";
DdlCat1.DataBind();
Run Code Online (Sandbox Code Playgroud)
"source"是一本字典:
Dictionary<int, string> source = new Dictionary<int, string>();
Run Code Online (Sandbox Code Playgroud)
selectedIndexChanged方法如下所示:
public void DropDown1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList temp = (DropDownList)sender;
Console.WriteLine(temp.SelectedValue);
}
Run Code Online (Sandbox Code Playgroud)
现在让我说我的下拉列表中有item1,item2和item3.目前我选择了item1.现在问题是,如果我在item2中单击,则会触发SelectIndexChanged方法但是SelectedValue始终保持在"item1".那么,我做错了什么?
我有一个标准的C#队列,声明如下:
private Queue<DeployJob> _solutionQueue = new Queue<DeployJob>();
Run Code Online (Sandbox Code Playgroud)
现在我想将这个队列绑定到一个DataGridView,它放在一个winform中.对于"绑定",我的意思是每次我dequeue
或enqueue
队列中的项目DataGridView
得到更新(这样它总是代表队列的状态).
我试图用这种方式绑定它:
jobGridView.DataSource = _solutionQueue;
Run Code Online (Sandbox Code Playgroud)
但它不起作用,即使我使用update
或refresh
方法.如果您需要更多代码,请随时问:)
假设我有以下字符串:
string test = " False";
我无法循环字符串的字符,因为我需要为1744字符串执行此操作,那么这将是很多工作.
你知道微软是否有一种方法可以用来删除这个空格?
像这样: string test2 = test.DeleteFirstWhitespace();
谢谢
c# ×8
asp.net ×3
.net ×1
caml ×1
children ×1
content-type ×1
data-binding ×1
datagridview ×1
list ×1
queue ×1
sharepoint ×1
splist ×1
splistitem ×1
string ×1
whitespace ×1
winforms ×1