5

I have profile provider in my web.config

    <profile defaultProvider="MyProvider">
      <providers>
.......
      <properties>
        <add name="CustomField1" type="string" />
        <add name="CustomField2" type="string" />
        <add name="CustomField3" type="string" />
        <add name="CustomField4" type="string" />
      </properties>
    </profile>

How can I get string[] array containing all avaliable properties (CustomField1, CustomField2....)

Edit: Found working solution but not sure if it's the best and easiest one.

var allCustomProperties =
                    profile.GetType().GetProperties().Where(l => l.PropertyType.Name == "String" && l.CanWrite == true).Select(
                        l => l.Name).ToArray();
Dmytro Leonenko
  • 1,443
  • 5
  • 19
  • 30

1 Answers1

9

I'd go with that:

string[] props = ProfileBase.Properties.Cast<SettingsProperty>()
            .Select( p => p.Name ).ToArray();

You have to import both System.Web.Profile and System.Configuration namespaces.

Piotr Ratajczak
  • 296
  • 1
  • 3