0

I am trying to use this method but I am confused about what/how to pass the parameter to it.

void SaveReport(Telerik.Reporting.Report report, string fileName)
{
    ReportProcessor reportProcessor = new ReportProcessor();
    Telerik.Reporting.InstanceReportSource instanceReportSource = 
        new Telerik.Reporting.InstanceReportSource();
    instanceReportSource.ReportDocument = report;
    RenderingResult result = 
        reportProcessor.RenderReport("PDF", instanceReportSource, null);

    using (FileStream fs = new FileStream(fileName, FileMode.Create))
    {
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
    }
}

I have tried to pass the name of the report I need to export, which is in a library in this way:

2nd Modification

protected void Button1_Click(object sender, EventArgs e)
{
    string fileName = "SS";
    var report = BOMreports.Report321();
    SaveReport(report, fileName );
}

But I keep getting the error "cannot access method on a namespace" on the var report. I do I solve this?

8
  • 1
    What is BOMReports? A class or a namespace? Commented Jul 6, 2014 at 6:13
  • It is a class which contains several reports. Commented Jul 6, 2014 at 6:14
  • 1
    Why are the arguments to SaveReport are in the wrong order? In method signature it's report, fileName but when invoked you're passing fileName, report. Commented Jul 6, 2014 at 6:15
  • Are you sure you're getting the error from that line? Try var report = BOMReports.Report321(); SaveReport(filename, report); on two lines. See which line gets the error. Commented Jul 6, 2014 at 6:15
  • 1
    Show BOMreports code. Commented Jul 6, 2014 at 6:26

1 Answer 1

1

It seems that you have a conflict in the BOMreports class and a name space with the same name. And since your namespace is in the same assembly as your code and the class is in another assembly, the compiler refers to it when you use the name in your code. Try to access the class with its fully identifier as:

namespace.BOMreports.Report321();

Another thing, make sure Report321 is a static method that returns an object of Telerik.Reporting.Report.

Addition

If Report321 is a class in BOMreports, the you are doing it wrong. What you need to do is to instantiate it as the following:

var report = new BOMreports.Report321();
Sign up to request clarification or add additional context in comments.

5 Comments

I investigated your hint but unless I am missing something from your answer, there are no conflicts in such DLL. The namespace is BOMreports and the name of the file in such name space is a class "Report321" which is working fine in several other context.
@Nullbyte So Report321 is not a method ?
No, BOMreports is a class library containg several classes of which Report321 is one of these.
You are a star! That was the problem. with your updated answer the problem is solved.
@Nullbyte I am not a star :p I guess you need some coffee. That's all :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.