2011-08-17 70 views
4

嗨StackOverflow成員!Sharepoint 2010 - 向用戶添加示例數據字段類型

我在Visual Studio(槽XML)中開發自定義列表。我創建了列表定義(帶有內容類型)並添加了列表實例。

這裏是我的名單中的schema.xml:

<?xml version="1.0" encoding="utf-8"?> 
<List xmlns:ows="Microsoft SharePoint" Title="Teams" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Teams" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/"> 
<MetaData> 
<ContentTypes> 
    <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313DE94" /> 
</ContentTypes> 
<Fields> 
    <Field Type="User" Name="Employee" DisplayName="Employee" Required="TRUE" ID="{7B18E941-BAAD-453A-895C-39579AB5A9F1}" Group="Sample Group" /> 
    <Field Type="Boolean" Name="Manager" DisplayName="Manager" ID="{9FC927CC-45EB-4E9E-8F25-18AAEDF7DCAF}" Group="Sample Group" /> 
</Fields> 
<Views> 
    <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE"> 
    <Toolbar Type="Standard" /> 
    <XslLink Default="TRUE">main.xsl</XslLink> 
    <RowLimit Paged="TRUE">30</RowLimit> 
    <ViewFields>  
     <FieldRef Name="Employee" /> 
     <FieldRef Name="Manager" /> 
    </ViewFields> 
    <Query> 
     <OrderBy> 
     <FieldRef Name="Modified" Ascending="FALSE"></FieldRef> 
     </OrderBy> 
    </Query> 
    <ParameterBindings> 
     <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" /> 
     <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> 
     <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" /> 
    </ParameterBindings> 
    </View> 
    <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx"> 
    <Toolbar Type="Standard" /> 
    <XslLink Default="TRUE">main.xsl</XslLink> 
    <RowLimit Paged="TRUE">30</RowLimit> 
    <ViewFields> 
     <FieldRef Name="LinkTitle"></FieldRef>  
     <FieldRef Name="Employee" /> 
     <FieldRef Name="Manager" /> 
    </ViewFields> 
    <Query> 
     <OrderBy> 
     <FieldRef Name="ID"></FieldRef> 
     </OrderBy> 
    </Query> 
    <ParameterBindings> 
     <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> 
     <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" /> 
    </ParameterBindings> 
    </View> 
</Views> 
<Forms> 
    <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
    <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
    <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
</Forms> 

與列表模板和內容類型elements.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. --> 
<ListTemplate 
    Name="TeamList" 
    Type="10000" 
    BaseType="0" 
    OnQuickLaunch="TRUE" 
    SecurityBits="11" 
    Sequence="410" 
    DisplayName="TeamList" 
    Description="My List Definition" 
    Image="/_layouts/images/itgen.png"> 

</ListTemplate> 
<ContentType 
    ID="0x010089E3E6DB8C9B4B3FBB980447E313DE94" 
    Name="Team Member" 
    Group="Sample Group" 
    Description="" 
    Version="0"> 
    <FieldRefs> 
     <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Hidden="TRUE" /> 
     <FieldRef ID="{7B18E941-BAAD-453A-895C-39579AB5A9F1}" /> 
     <FieldRef ID="{9FC927CC-45EB-4E9E-8F25-18AAEDF7DCAF}" /> 
    </FieldRefs> 
</ContentType> 

<Field Type="User" Name="Employee" DisplayName="Employee" Required="TRUE" ID="{7B18E941-BAAD-453A-895C-39579AB5A9F1}" Group="Sample Group" /> 
<Field Type="Boolean" Name="Manager" DisplayName="Manager" ID="{9FC927CC-45EB-4E9E-8F25-18AAEDF7DCAF}" Group="Sample Group" /> 

</Elements> 

的問題是:如何將示例數據添加到此列表中?特別是對於「用戶」類型的字段?

我試圖在列表實例元素添加此代碼:

<ListInstance Title="TeamList" 
      OnQuickLaunch="TRUE" 
      TemplateType="10000" 
      Url="Lists/TeamList" 
      Description="TeamList"> 
    <Data> 
     <Rows> 
      <Row> 
       <Field Name="Employee">CONTOSO\joses</Field> 
       <Field Name="Manager">true</Field> 
      </Row> 
     </Rows> 
    </Data> 

但是,錯誤occures:發生在一個部署步驟「激活功能」錯誤:至少有一個字段類型未正確安裝。任何幫助使它與對話框工作將非常感激。

+0

創建沒有示例數據工作的ListInstance?我不認爲你可以指定「Zespół」作爲列表標題/網址,錯誤可能是誤導... – int32 2011-08-17 11:22:04

+0

是的。它沒有樣本數據。對於誤導性的ListInstance名稱感到抱歉 - 我忘了從我的環境語言(PL)翻譯這部分。 – Redzio 2011-08-17 12:13:04

+0

呃好吧,這沒問題。 CONTOSO \ joses是否存在?如果是的話,恐怕我沒有更多的想法可能會導致這種例外。如果沒有自定義代碼,也許甚至不可能實現這個功能,即EventReceiver – int32 2011-08-17 13:07:45

回答

6

A User字段是特殊類型的查找字段。如此,文本值以ID;#TextValue的格式表示。而且,確實,這只是重要的ID。價值在很大程度上被忽略。這可能是一個問題,因爲儘管用戶名總是相同的,但表示該用戶的ID將從網站集合更改爲網站集。

你行XML應該是這個樣子:

<Data> 
    <Rows> 
     <Row> 
      <Field Name="Employee">99;#CONTOSO\joses</Field> 
      <Field Name="Manager">true</Field> 
     </Row> 
    </Rows> 
</Data> 

你說,這是被部署到現有的網站,這樣你就可以瀏覽到CONTOSO \約西的用戶信息頁面。該ID將位於URL的查詢字符串中。但請注意,即使該功能在此站點中正常運行,也不能保證該功能在其他網站集合中可以正常工作。

爲了避免這個問題,我通常會使用Feature Receiver來預先填充帶有用戶字段的列表,而不是使用XML爲種子實例種子。我更喜歡EnsureUser,因爲如果用戶不存在,它會將用戶添加到網站。

3

這也將工作:

<Field Name="Employee">-1;#CONTOSO\joses</Field> 
1

在SharePoint 2013使用-1;#填補User類型的柱是不容易出錯。

如果你拼錯或提供一個不存在的用戶:

<Field Name="Employee">-1;#domain\nonexistent account or misspelled</Field> 

不會創建記錄。

顯式指定ID可能會導致分配現有的組或用戶,並且可能很難調試。特別是如果你還爲ID列的值:

<Field Name="ID">1</Field> 
<Field Name="Employee">1;#domain\nonexistent account or misspelled</Field> 

既有豐富的和喬納森的回答是正確的,只是想澄清,並由於低代表無法發表評論。

相關問題