views:

46

answers:

1

Hello,

we are using the asp.net profiles provider in our app and I need to update one particular property for most of our users. Does anyone have a console app or sample code written? We are not storing the properties in string format. This binary stream is in the aspnet_Profile table.

thanks, hp

+1  A: 

You can do something like this fairly easily:

Membership.GetAllUsers().Cast<MembershipUser>()
    .Where(u => true /*insert your criteria here*/)
    .ToList().ForEach(user =>
    {
        var p = ProfileBase.Create(user.UserName, true);

        // do whatever you want to the profile here
        int counter = (int)p["Counter"];
        counter++;
        p["Counter"] = counter;

        p.Save();
    });

The above code will work as-is in any handler of your site, but if you want to do it with a console app, simply copy the <system.web> section from your web.config to the app.config of the console app.

caveat: if you are using the default provider connection string, localSqlServer, you will need to create a new connection string explicitly pointing to the .mdf as only web applications have a concept of DATADIRECTORY (app_data).

Sky Sanders