This code works fine within a Kentico website:
var users = UserInfoProvider.GetUsers();
for (int x = 0; x < users.Count(); x++
{
UserInfo currentUser = users.ElementAt(x);
currentUser.SetValue("AcceptsAlerts", equivalentSubscriber.Status != SubscriberStatus.Unsubscribed);
UserInfoProvider.SetUserInfo(currentUser);
}
When I move the code to a console app, any calls to UserInfoProvider result in the error: "Object type 'cms.usersettings' not found"
For the initial call to get the users, I can do it like this in the console app:
DataSet usersds = new CMS.DataEngine.DataQuery("cms.user.selectall").Execute();
then loop through Table1 of the dataset using the user data:
UserInfo currentUser = new UserInfo(dtUsers.Rows[x]);
All is fine and working, until I come to write the updated user back to the database. I cannot find another way of writing the data apart from calling:
UserInfoProvider.SetUserInfo(currentUser);
Does anyone know another way to save the user data? or to resolve the error. The error is a runtime error and as far as I know, I have referenced everything I need to. The field I am editing is a custom field added to the cmsUser table.
using statements for info:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.Membership;