如何在sharepoint用户配置文件中读取由分号分隔的值?

时间:2013-03-22 05:02:54

标签: c# .net sharepoint sharepoint-2010

我在sharepoint网站上的用户个人资料中有一个名为Responsibility的字段,其中包含的值类似于“abc; def; ghi”。我想将这些值读入数组。 当我使用[propertyconstants.responsibility] .value时,只读取abc。如何分别阅读abc,def和ghi?

我的代码是:

string xpUser = up[PropertyConstants.Responsibility].Value.ToString();
string[] expUser = xpUser.Split(';');

3 个答案:

答案 0 :(得分:0)

我假设你有这样的东西

string xpUser =  "abc; def; ghi";

你想要abe,def& ghi分开然后这样做

string[] arrayUser = xpUser.Split(';');
foreach(string user in arrayUser)
{
   //Do what you want with **user** , now this user will have values that you want 1 by 1
   //if you see the value of user, 1st time you will get abc, 2nd time def , 3rd time ghi
}

答案 1 :(得分:0)

您的回答似乎暗示您想要通过令牌“;”分开(因为您说您想要“abc”而不是“abc”)

这是一个演示这样做的单元测试。

 [Test]
 public void SplitStringByString()
 {
    string input = "abc; def; ghi";
    string[] expected = new[] {"abc", "def", "ghi"};

    var result = input.Split(new [] { "; " }, StringSplitOptions.None);

    Assert.That(result, Is.EquivalentTo(expected));
 }

答案 2 :(得分:0)

感谢大家的帮助。

我终于找到了

的解决方案
 var strUser = up.GetProfileValueCollection(PropertyConstants.Responsibility);