using Sitecore.Shell.Framework.Commands;
using System;
using Sitecore.Web.UI.Sheer;
using System.IO;
using Sitecore.SecurityModel;
using System.Text;
using Sitecore.Diagnostics;
namespace SitecoreCustom.Web.Extensions.Commands
{
public class ExportSitecoreUsers : Command
{
string filepath = string.Empty;
public override void Execute(CommandContext context)
{
try
{
CreateFile();
if (!string.IsNullOrWhiteSpace(filepath))
SheerResponse.Download(filepath);
}
catch (Exception ex)
{
Log.Error(ex.Message, ex);
SheerResponse.Alert("Error Occurred: Please try again");
}
}
///
/// Create csv file with list of users.
///
private void CreateFile()
{
string fileExtension = ".csv";
string path = Sitecore.Configuration.Settings.DataFolder + "Export User";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileName = "Sitecore_User";
fileName = fileName + "-" + DateTime.Now.ToString("MM-dd-yyyy_HH-mm-ss");
filepath = path + @"\" + fileName + fileExtension;
using (new SecurityDisabler())
{
var users = Sitecore.Security.Accounts.UserManager.GetUsers();
StringBuilder records = new StringBuilder();
records.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
"User Name",
"Domain",
"Fully Qualified Name",
"Full Name",
"Email",
"Comment",
"Language",
"Locked"));
foreach (var user in users)
{
try
{
if (user != null)
{
records.Append(Environment.NewLine);
records.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
user.LocalName,
user.Domain.Name,
user.DisplayName,
user.Profile.FullName,
user.Profile.Email,
user.Profile.Comment,
user.Profile.ClientLanguage,
user.Profile.State));
}
}
catch (Exception ex)
{
Log.Error(ex.Message, ex);
}
}
using (var writer = new StreamWriter(filepath, false))
{
writer.WriteLine(records.ToString());
writer.Close();
}
}
}
}
}
These custom code files can also be downloaded from here
In Sitecore, while working for real-time projects, you may get scenarios where you would see a need to customize you rendering output to serialze. Sitecore provides three different ways of customizing your rendering output with Sitecore JSS. They are as below. • Use JSS GraphQL Support - Using Integrated GraphQL queries • Use Out-of-the-box Rendering Content Resolvers - Using Sitecore JSS built-in Rendering Content Resolvers • Implementing a Custom Rendering Content Resolvers by inheriting RenderingContentsResolver Why Customization? In Sitecore development, many times we encounter scenarios to deal with hierarchical item structures like multi-level menu, product category, product sub-category, product details, forms etc., and even, in case where there is a need to combine the Sitecore data with any non-Sitecore data. In these types, Sitecore JSS is not able to serialize item structures with sub-hierarchies into JSON. Sitecore Jss allow us custiomize in...
Comments
Post a Comment