Download report File in plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi,

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();
        }
    }
7 years ago
it seems to do with the architecture how plugin views work in nopcommerce, have a look here https://paragdaraji.wordpress.com/2015/05/07/file-download-issue-with-sitecore-mvc-and-resolution/ they seem to have the exact same issue, but when i tried the redirect solution it still didnt help, since its still falling at the injection of nop plugin view.

no idea how to get around that.

anyone with input on that?
7 years ago
can you tell me the result of csvStringData ?
7 years ago
i figured out the issue,
i took down these attributes


        [HttpPost, ActionName("Configure")]
        [ChildActionOnly]
        [FormValueRequired("report")]


and in the view i made it as an anchor with an href to the method without submitting the form and it works now perfect.
7 years ago
Auto99 wrote:
i figured out the issue,
i took down these attributes


        [HttpPost, ActionName("Configure")]
        [ChildActionOnly]
        [FormValueRequired("report")]


and in the view i made it as an anchor with an href to the method without submitting the form and it works now perfect.


Yes . ChildActionOnly was a problem.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.