d.SPTextBuilder

Заполнение текстовых шаблонов из элемента списка Sharepoint. 

Имеем список с элементами:

Создаем провайдер доступа к элементу:
 
internal class SampleListItemProvider : d.SPTextBuilder.Providers.SPListItemBaseProvider
{
    #region Properties
    [TextBuilderMethod]
    public int CustomProperty
    {
        get {return 45;}
    }
    [TextBuilderMethod]
    public DateTime CustomFormatProperty
    {
        get {return DateTime.Now;}
    }
    #endregion Properties
	
    #region Constructors
    public SampleListItemProvider(Microsoft.SharePoint.SPListItem item) : base(item)
    {
    }
    #endregion Constructors

    #region Methods
    [TextBuilderMethod]
    public int CustomMethodNoParams()
    {
        return 1;
    }
    [TextBuilderMethod]
    public int CustomMethodWithParams(int a, int b)
    {
        return a + b;
    }
    #endregion Methods
}

 

Создаем парсер:
TextBuilder textBuilder = 
new TextBuilder(new SampleListItemProvider(item));

string mailTemplate = 
    "ItemTitle: {%Field(Title)%}" + Environment.NewLine +
    "NoteFld: {%Field(NoteFld)%}" + Environment.NewLine +
    "ChoiceFld: {%Field(ChoiceFld)%}" + Environment.NewLine +
    "NumberFld: {%Field(NumberFld)%}" + Environment.NewLine +
    "CurrencyFld: {%Field(CurrencyFld)%}" + Environment.NewLine +
    "DateTimeFld: {%Field(DateTimeFld)%}" + Environment.NewLine +
    "LookupFld: {%Field(LookupFld)%}" + Environment.NewLine +
    "BooleanFld: {%Field(BooleanFld)%}" + Environment.NewLine +
    "UserFld: {%Field(UserFld)%}" + Environment.NewLine +
    "URLFld: {%Field(URLFld)%}" + Environment.NewLine +
    "CustomProperty: {%CustomProperty%}" + Environment.NewLine +
    "CustomMethodNoParams: {%CustomMethodNoParams%}" + Environment.NewLine +
    "CustomMethodWithParams: {%CustomMethodWithParams(6,9)%}" + Environment.NewLine +
    "CustomFormatProperty: {%CustomFormatProperty:dd/MM/yyyy%}";
    
	string output = textBuilder.Parse(mailTemplate);

 

Результат:

ItemTitle: Hello world!
NoteFld: <div class="ExternalClass27392DF017794231B6A661BFB1A566E1"><p>​Big Text<br></p><p>Note Input<br></p></div>
ChoiceFld: Вариант 2
NumberFld: 999
CurrencyFld: 123,00 ₽
DateTimeFld: 09.08.2017
LookupFld: <a href="http://***/_layouts/15/listform.aspx?PageType=4&ListId={d23e63e7-94d2-4a0a-b569-8969eeed2a25}&ID=4&RootFolder=*">Гибкость в принятии решений</a>
BooleanFld: Yes
UserFld: <span class="ms-noWrap"><span class='ms-imnSpan'><a href='#' onclick='IMNImageOnClick(event);return false;' class='ms-imnlink ms-spimn-presenceLink' ><span class='ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10'><img name='imnmark' class='ms-spimn-img ms-spimn-presence-disconnected-10x10x32' title='' ShowOfflinePawn='1' src='/_layouts/15/images/spimn.png?rev=23' alt='No presence information' sip='a@a.ru' id='imn_1,type=smtp'/></span></a></span><span class="ms-noWrap ms-imnSpan"><a href='#' onclick='IMNImageOnClick(event);return false;' class='ms-imnlink' tabIndex='-1'><img name='imnmark' class='ms-hide' title='' ShowOfflinePawn='1' src='/_layouts/15/images/blank.gif?rev=23' alt='' sip='a@a.ru' id='imn_2,type=smtp'/></a><a class="ms-subtleLink" onclick="GoToLinkOrDialogNewWindow(this);return false;" href="/MatrixPoll/_layouts/15/userdisp.aspx?ID=59">Дмитрий Андреевич</a></span></span>
URLFld: <a href="http://****/Lists/test/EditForm.aspx">HyperLinkSample</a>
CustomProperty: 45
CustomMethodNoParams: 1
CustomMethodWithParams: 15

Ссылка:

https://github.com/dzsoft-ru/d.SPTextBuilder

 

Добавить комментарий

Loading