Periodic report of all Episerver users?

Vote:
 

Is it possible to create a periodic (scheduled job) report of all EpiServer users that can be sent to someone? Preferabbly in .csv format? 

I would really appreciate any pointing in the right direction or any code examples that I can look into.

How would you recommend to best go about this?

#259472
Jul 26, 2021 12:21
Vote:
 

Are you talking about backend users or users of the front end of your website? What authentication system do you have in place? E.g. the OOTB asp.net identity, azure ad/OAuth provider?

#259476
Jul 26, 2021 13:28
Vote:
 

Sorry I meant backend users. I think it is the OOTB authentication.

#259477
Jul 26, 2021 13:50
Vote:
 

Get an instance of the user store

var userStore = new UserStore<ApplicationUser>(new IdentityDbContext(connectionString));

Substituing whatever user you're using if you're using any other role than the standard ApplicationUser else just user that then you can access all users via

userStore.Users
#259478
Jul 26, 2021 13:58
Vote:
 

If you are using AspNetIdentity, you can use UserManager<TUser>.Users (or ApplicationUserManager<TUser>), which TUser is your implementation of ApplicationUser

#259513
Jul 27, 2021 6:27
Scott Reed - Jul 27, 2021 8:01
What methods will work for getting multiple users? I did double check these first but they've only got methods for working with single users, I couldn't see any listing methods and the search ones require parameters.
Quan Mai - Jul 27, 2021 10:43
There is no such method, but this return IQueryable
Scott Reed - Jul 27, 2021 10:45
Ah yes I completely missed the properties when I saw. Apologies didn't see the .Users part of your comment. It's funny I would usually use the UserManager but for some reason I doubted myself when I checked it. Busy day tho
Quan Mai - Jul 28, 2021 7:01
No worries mate. We've been all there. How's life?
Scott Reed - Jul 28, 2021 8:31
Yeah not too bad, heavily in a load of commerce projects for lots of different clients. Enjoying playing with the .net 5 project and such. :-) Your blogs pop up on many a project we do as I'm sure they do for everyone. Isn't there a new version of your book on the way?
Quan Mai - Jul 28, 2021 10:49
Yes, but I'm a bit stuck with vacations and kids to make a progress on that
Scott Reed - Aug 02, 2021 8:03
haha, well family is the most important thing...at least that's what the fast and furious franchise tell me :p Have great vacations Quan :-) :-) I'm just back from a half week off, always nice to rest and recover
Vote:
 

Thank you for the suggestions so far. How hard would it be to periodically generate a report in .csv format and have it sent to a location? Or what other suggestions would you have to implement something similar?

#259564
Jul 28, 2021 9:06
Daniel Ovaska - Jul 29, 2021 18:43
A day or two of development probably depending on skill level. An hour or two for a skilled senior developer depending on what information you need
Vote:
 

It is just another scheduled job, so the "periodically" task is handled for you, other than that it is normal .net code Scheduled jobs | Optimizely Developer Community

#259568
Jul 28, 2021 10:49
Vote:
 

Thank you all for the info so far. Some more questions, any recommendations on the best tools for creating a .csv file? Also would you recommend to use the built in CMS E-Mailing capabilities to send this report to someone, or is better/safer to have the file sent/stored at a specific location?

#259673
Jul 30, 2021 7:07
Scott Reed - Aug 02, 2021 8:03
I've used the library LINQ to CSV before and it worked well
Vote:
 

I think you are over thinking it. Check your requirements to make sure you fulfill it, then do a minimal approach. You can always improve later

A search for "C# convert List<T> to csv" would be enough for first question.

Cms has no builtin mail capacity but you can simply write one using .net. Depends on what you need, but you might store the csv as an asset with specific access rights granted to certain people, and send the url to those.

#259674
Jul 30, 2021 7:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.