We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Save report in FieExplorer

Thread ID:

Created:

Updated:

Platform:

Replies:

130341 May 8,2017 06:39 AM May 10,2017 06:54 AM ASP.NET MVC 1
loading
Tags: ReportViewer
Anis
Asked On May 8, 2017 06:39 AM

Hi,
I'm trying to generate and save reports of each product in a specific folder in FileExplorer. The function fetch in order table and if it finds a new order it create a folder and add the ordered product report to that folder.
I don't know where is the error. Can you help me to achieve this?

foreach (var o in order)
{
      var path = Server.MapPath("~/FileExplorerContent/" + o.CustomerName + "/" + o.OrderId);
        Directory.CreateDirectory(path);
                try
                {
                    foreach (var p in db.Product)
                    {
                        if (p.Pid == o.Pid)
                        {
                            string fileName = null;
                            HttpContext httpContext = System.Web.HttpContext.Current;
                            ReportWriter reportWriter = new ReportWriter(path);
                            reportWriter.ReportPath = Server.MapPath("~/App_Data/Report.rdl");
                            reportWriter.ReportProcessingMode = ProcessingMode.Remote;

                            List<ReportParameter> parameters = new List<ReportParameter>();
                            parameters.Add(new ReportParameter() { Name = "Pid", Labels = new List<string>() { o.Pid }, Values = new List<string>() { o.Pid } });
                            reportWriter.SetParameters(parameters);
                            

                            fileName = o.Pid+ ".pdf";

                            reportWriter.Save(fileName, WriterFormat.PDF, httpContext.Response);
                        }
                    }
                }
                catch (Exception ex){}
            }
        }


Yuvaraj Devarajan [Syncfusion]
Replied On May 10, 2017 06:54 AM

Hi Anis, 

Thanks for contacting Syncfusion support. 

We can generate and save the report PDF file directly in dynamically created directory by passing the file path name and format in save method as shown in below code example, 

public ActionResult Index(string button) 
        { 
            try 
            {               
                var path = Server.MapPath("~/App_Data/Test"); 
                Directory.CreateDirectory(path); 
                string fileName = null;                
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter(); 
                reportWriter.ReportPath = Server.MapPath("~/App_Data/Report.rdl"); 
                reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
                List<ReportParameter> parameters = new List<ReportParameter>(); 
                parameters.Add(new ReportParameter() { Name = "Ord", Labels = new List<string>() { "AAA" }, Values = new List<string>() { "AAA" } }); 
                reportWriter.SetParameters(parameters); 
 
                fileName = "file.pdf"; 
                reportWriter.Save(path+"/"+fileName, WriterFormat.PDF);                                          
            } 
            catch 
            { 
            } 
            return View(); 
        } 

We have prepared a sample and it can be downloaded from below location, 

Please refer to the below UG document for more detail, 

If the problem still occurs, then revert the sample with issue reproducible procedure to validate the mentioned issue at our end. 

Regards, 
Yuvaraj D. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;