簡體   English   中英

網站集上的列查詢不包含內容

[英]Lookup to column on site collection does not contain contents

我創建一個網站集列,該列本身可以查詢該網站集內的列表。 我使用CSOM創建此列:

    string contextUrl = "http://company.example.com/sites/mysite/subsite";

    SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext.Current);
    ClientContext clientContext = new ClientContext(contextUrl);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();

    Web rootWeb = clientContext.Site.RootWeb;
    clientContext.Load(rootWeb);

    // Add List containing target column
    ListCreationInformation targetListInfo = new ListCreationInformation();
    targetListInfo.Title = "TargetListTitle";
    targetListInfo.TemplateType = (int)ListTemplateType.GenericList;

    List targetList = web.Lists.Add(targetListInfo);           
    targetList.Update();
    clientContext.Load(targetList);
    clientContext.ExecuteQuery();


    // Update Title
    FieldCollection techListFields = targetList.Fields;
    clientContext.Load(techListFields);
    clientContext.ExecuteQuery();

    // Create Site Lookupcolumns
    var techListID = targetList.Id;

    FieldCollection colSCFields = rootWeb.Fields;
    clientContext.Load(colSCFields);
    clientContext.ExecuteQuery();

    var lookupSchema = "<Field Type='Lookup' DisplayName='Magic' Required='FALSE' List='" + techListID + "' ShowField='Title' StaticName='Magic' Name='Magic'/>";
    colSCFields.AddFieldAsXml(lookupSchema, false, AddFieldOptions.AddFieldInternalNameHint);

    clientContext.ExecuteQuery();

(有關完整的信息,我添加了所有行,但是關鍵部分從"// Create Site Lookupcolumns"下面開始)

正在創建site列,但是當我在子站點(手動或通過程序)內部的列表上的該列上使用查找時,該查找字段中的下拉列表不顯示任何內容 (該行為看起來像在目標列存在之前創建的查找列)

您需要在字段xml定義中指定WebId屬性值(將其設置為子站點ID),如下所示:

var lookupSchema = "<Field Type='Lookup' DisplayName='Magic' Required='FALSE' WebId='" + web.Id + "' List='" + techListID + "' ShowField='Title' StaticName='Magic' Name='Magic'/>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM