You are viewing limited content. For full access, please sign in.

Question

Question

Reading field language value by SDK

asked on August 18, 2019

Dears ,

In Administration Console , there is an option to set the displayed name for the field based on current language.

 Can we read these attributes using the SDK?

 

 

0 0

Replies

replied on August 19, 2019

The field languages can be retrieved with the Field.GetExtendedProperties method, here is some sample code:

List<PropValue> propertyNames = new List<PropValue>();
propertyNames.Add(new PropValue()
{
    Name = "LF:Name",
    Namespace = "http://laserfiche.com/namespaces/cr/fields/"
});

// Get all field extended properties
List<PropResponse> AllFieldProperties = Field.GetExtendedProperties(propertyNames, session);

Dictionary<string, Dictionary<string, string>> localizedNameDict = new Dictionary<string, Dictionary<string, string>>();

foreach (PropResponse response in AllFieldProperties)
{
    if (response.PropStat[0].Status.Contains("200"))
    {
        string fieldUrl = System.Web.HttpUtility.UrlDecode(response.Href);

        // Strip off the +LF/prop/
        int index = fieldUrl.IndexOf("+LF/prop/") + 9;
        string fieldName = fieldUrl.Substring(index);

        localizedNameDict[fieldName] = new Dictionary<string, string>();

        foreach (PropValue propVal in response.PropStat[0].Props)
        {
            // Parse the extended properties to get the localized names
            List<string> segments = propVal.Value.Split(new[] { '\r', '\n' }).ToList();
            segments.RemoveAll(item => String.IsNullOrEmpty(item));

            foreach (string prop in segments)
            {
                // Each line looks like this:
                // en=English Name
                // fr=French Name
                var split = prop.IndexOf('=');
                if (split == -1)
                    continue;

                string languageCode = prop.Substring(0, split).Trim().ToLower();
                string localizedName = prop.Substring(split + 1).Trim();

                // Add this localized name to the dictionary
                localizedNameDict[fieldName][languageCode] = localizedName;
                Console.WriteLine($"{fieldName}-{languageCode}: {localizedName}");
            }
        }
    }
}

 

2 0
replied on October 3, 2019

I can't find the GetExtendedProperties 

Could you please tell me the SDK refrences to use ?

0 0
replied on October 3, 2019

Use Laserfiche.RepositoryAccess 10.3 or newer.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.