i am having now an issue with a report that i want to be available inside a plugin, but i am getting this error at the config view from nop that is trying to call my config error is this > "OutputStream is not available when a custom TextWriter is used."
here is my code any help would be appreciated.
[HttpPost, ActionName("Configure")]
[ChildActionOnly]
[FormValueRequired("report")]
public ActionResult GenerateReport(ConfigurationModel model)
{
try
{
var productsForReview = _productService.SearchProducts(overridePublished: true)
.Where(q => q.StockQuantity > 0 && q.Deleted == false)
.Select(x => new
{
Id = x.Id,
Sku = x.Sku
});
var csvStringData = productsForReview.ToCsvData();
return File(Encoding.UTF8.GetBytes(csvStringData), "text/csv", "test.txt");
}
catch (Exception exc)
{
ErrorNotification(exc.Message);
_logger.Error(exc.Message, exc);
return null;
}
}
and here is my extension method for building the string
public static class Extensions
{
public static string ToCsvData<T>(this IEnumerable<T> objList)
{
if (objList == null)
{
throw new ArgumentNullException("List", "Value can not be null or Nothing!");
}
StringBuilder sb = new StringBuilder();
List<PropertyInfo> properties = objList.First().GetType().GetProperties().ToList();
var propCount = properties.Count();
for (int i = 0; i < propCount; i++)
{
sb.Append(properties[i].Name);
if(i < propCount - 1)
sb.Append(",");
}
sb.Append(Environment.NewLine);
foreach (var item in objList)
{
for (int i = 0; i < propCount; i++)
{
sb.Append(properties[i].GetValue(item, null));
if (i < propCount - 1)
sb.Append(",");
};
sb.Append(Environment.NewLine);
}
return sb.ToString();
}
}