Quantcast
Channel: SQL Server Reporting Services
Viewing all articles
Browse latest Browse all 1418

rdlc Access to the path denied

$
0
0

In my web forms application, C#, .Net 4.0, I want rdlc report to print directly to printer. The rdlc report is good in report viewer, and the data table has 4 records in it, so I know the report and data are good.

I get an error: Access to the path 'C:\\Program Files (x86)\\IIS Express\\Report1_0.EMF' is denied.

at code line: Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);

I referred to this article: https://msdn.microsoft.com/en-us/library/ms252091(v=vs.120).aspx

Also I don't understand why the compiler is going to IIS Express, why can't it just go to the reports folder in my solution to get the report? I went to C:\Program Files (x86)\IIS Express in windows explorer and did NOT find any files starting with word Report.

Also I tried changing the path to my solution path... C:\Users\myName\Documents\Visual Studio 2013\Projects\MyProject\Reports\Report1.rdlc and still I get the same Access To Path Denied error.

Here is my code, which is like the article linked above :

private int m_currentPageIndex;
private IList<Stream> m_streams;

private void Run()
{
LocalReport report = new LocalReport();
report.ReportPath = @"Reports\Report1.rdlc";
report.DataSources.Add(new ReportDataSource("DataSet1", LoadData()));

Export(report);

m_currentPageIndex = 0;
Print();
}

private DataTable LoadData()
{
DataTable dtFunding = Process.MyToolBox.SQLServerSelectRowsIntoDataTable("SELECT * FROM tblFunding WHERE [Status] = 'Test'");
return dtFunding;
}

private Stream CreateStream(string name, string fileNameExtension,
Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(name + "." + fileNameExtension,
FileMode.Create);

m_streams.Add(stream);
return stream;
}

private void Export(LocalReport report)
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.25in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.25in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);

foreach (Stream stream in m_streams)
stream.Position = 0;
}

private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, 0, 0);

m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}

private void Print()
{
const string printerName = "PS Driver for Universal Print";

if (m_streams == null || m_streams.Count == 0)
return;

PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".",
printerName);
Console.WriteLine(msg);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}

public void Dispose()
{
if (m_streams != null)
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}
}


Viewing all articles
Browse latest Browse all 1418


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>