使用 C#、ReportViewer 和 RDL 文件生成报告
Generating report using C#, ReportViewer and RDL file
我正在尝试使用 C# 和 RDL 文件生成报告。我已经按照示例进行操作,但无法继续进行。我收到错误:
"The path of the item 'sample.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)"。我曾尝试在路径前加一个斜杠,但没有成功。
我的报表服务器处于 本机 模式。我的两个主要问题是:
- 我需要参数吗?
- 我的 RDL 文件应该存储在哪里?
现在我正在我的项目中存储我的 RDL 文件。 (我觉得这不对)
这是一个代码片段:
const string path = "sample.rdl";
string url = "http://localhost/ReportServer";
string format = "PDF";
var rsReports = new Microsoft.Reporting.WebForms.ReportViewer
{
ProcessingMode = ProcessingMode.Remote,
ShowParameterPrompts = false
};
rsReports.ServerReport.ReportServerUrl = new Uri(url);
rsReports.ServerReport.ReportPath = Path.Combine("\" + Environment.CurrentDirectory, path);
rsReports.ServerReport.Refresh();
byte[] report = rsReports.ServerReport.Render(format.ToUpper());
return report;
您的 RDL 文件必须部署到 SSRS 服务器。您可以在 Visual Studio 中执行此操作。
右键单击您的报表项目并将报表服务器 url 设置为 http://localhost/ReportServer。
然后右键单击您的报告并 select 部署。
这会将您的报告和数据源部署到服务器。
您可以在更改此行后再次尝试您的代码....
rsReports.ServerReport.ReportPath = "/folder/reportName";
其中文件夹是报告发布到的服务器上文件夹的名称,reportName = "sample"(没有 .rdl)
您遇到的错误意味着路径必须以“/”开头
我正在尝试使用 C# 和 RDL 文件生成报告。我已经按照示例进行操作,但无法继续进行。我收到错误:
"The path of the item 'sample.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)"。我曾尝试在路径前加一个斜杠,但没有成功。
我的报表服务器处于 本机 模式。我的两个主要问题是:
- 我需要参数吗?
- 我的 RDL 文件应该存储在哪里?
现在我正在我的项目中存储我的 RDL 文件。 (我觉得这不对)
这是一个代码片段:
const string path = "sample.rdl";
string url = "http://localhost/ReportServer";
string format = "PDF";
var rsReports = new Microsoft.Reporting.WebForms.ReportViewer
{
ProcessingMode = ProcessingMode.Remote,
ShowParameterPrompts = false
};
rsReports.ServerReport.ReportServerUrl = new Uri(url);
rsReports.ServerReport.ReportPath = Path.Combine("\" + Environment.CurrentDirectory, path);
rsReports.ServerReport.Refresh();
byte[] report = rsReports.ServerReport.Render(format.ToUpper());
return report;
您的 RDL 文件必须部署到 SSRS 服务器。您可以在 Visual Studio 中执行此操作。 右键单击您的报表项目并将报表服务器 url 设置为 http://localhost/ReportServer。
然后右键单击您的报告并 select 部署。 这会将您的报告和数据源部署到服务器。
您可以在更改此行后再次尝试您的代码....
rsReports.ServerReport.ReportPath = "/folder/reportName";
其中文件夹是报告发布到的服务器上文件夹的名称,reportName = "sample"(没有 .rdl)
您遇到的错误意味着路径必须以“/”开头