Newbie question. I'm trying to write a c# class that can run a Crystal Report and save the result as a PDF file. My method currently only contains one line, which it is failing on:
ReportDocument reportDocument = new ReportDocument();
My "using" list contains:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
I've installed two NuGet packages, CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Shared. I'm just trying to follow some examples I've found from web surfing, and it seems that the examples I'm looking at always include these two packages.
The error I'm receiving on the ReportDocument instantiation above is:
"Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'. The system cannot find the file specified."
I suspect there's something obvious I'm missing that hasn't been installed. I do have Crystal Reports 2011, SAP Crystal Reports runtime engine for .NET Framework (32-bit), and Crystal Reports 2008 Runtime SP2 installed on my machine. I'm new to a lot of this and am not having much success finding the help I'm looking for.
Help is greatly appreciated. Thank you!
Please try this : first create instance of Crystal report, and you can simply Call Export To disk
RtpDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf")
Related
First of all, I'm working with Visual Studio 2015 (and can't upgrade VS version) and using a MySQL library. My using directives are
using System;
using System.Data;
using MySql.Data.MySqlClient;
And I'm trying to connect with a MySQL database with
MySqlConnection ms = new MySqlConnection(ConnectionData.ToString());
ms.Open();
The name of the function Open() is autocompleted ok, and I know it works fine on another projects I have been working on, but now I get this compiler error when trying to invoke the Open() function:
Must add an assembly reference 'System.Data, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I think my System.Data library is quite old, but I can't find a System.Data.dll file in my project (That way I could just replace it), anyone know how to just upgrade that library?
I am doing a project in C# and I have downloaded ExcelDataReader from codeplex and added it to my project reference. There is an error in namespace 'using Excel;' though I have added Excel, Excel.4.5, Microsoft.Office.Interop.Excel to my project references. I'm getting error where I have written
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
The errors are quoted below:
The type or namespace name 'ExcelDataReader' could not be found (are
you missing a using directive or an assembly reference?) The name
'ExcelReaderFactory does not exist in the current context
How to deal with these errors?
Thank you in advance.
PS:- I have added 'using Excel = Microsoft.Office.Interop.Excel' directive as well.
Go to Project -> Manage NuGet Packages..., in opened window select Browse tab and type Excel Data Reader, install it, at the top of your class add using Excel. Then you will be able to use interface IExcelDataReader.
Here is the source:
https://forums.asp.net/t/1981566.aspx?The+type+or+namespace+name+IExcelDataReader+could+not+be+found
Go to your project-> right click on References and click on Manage NuGet Packages a new tab would opened in your IDE if you are using VS 2015 or higher otherwise a pop window would open. enter package name and install.
In older versions of ExcelDataReader - like 2.1.2.3 - it uses an Excel namespace for itself, I mean that namespace is not related to Microsoft Office Excel, that I can suggest you to use alias for them:
using XlReader = Excel;
using Xl = Microsoft.Office.Interop.Excel;
...
var excelReader = XlReader.ExcelReaderFactory.CreateOpenXmlReader(stream);
But in newer version - like 3.1.0 - its namespace changed to ExcelDataReader;
You can install the package of ExcelDataReader 2.1.2.3 that will remove your compile exception.
I tried to use this code, to include Syncfusion Charts to the project
xmlns:charting="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.UWP"
but I get an error:
Undefined type "SfChart" in XML namespace "clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.UWP"
If I use standard using everything ok, but app package is too big, I don't need all controls from Syncfusion SDK.
xmlns:charting="using:Syncfusion.UI.Xaml.Charts"
It works fine with the following namespace while using assembly Syncfusion.SfChart.UWP
xmlns:charting="using:Syncfusion.UI.Xaml.Charts"
Regards,
Jessie
I am struggling with the following error when compiling my C# code with CSC - "error CS0234: The type or namespace name 'Core' does not exits in the namespace 'Microsoft.Office' (are you missing an assembly)"
I've had zero experience with object oriented programming before tackling this project. It involves automation of a couple devices through serial commands. Parameters are read from a native Excel file and data is written to Excel files that the code creates.
Here's what think maybe pertinent:
my compiling command: CSC /r:"C:\Data\Code\Microsoft.Office.Interop.Excel.dll" compiled.cs
I have the file Microsoft.Office.Interop.Excel.dll in the directory above. I found the file on my computer from something else that installed it. It is dated 2007.
I am using Office 2010
I installed Microsoft Office 2010: Primary Interop Assemblies Redistributable but can't tell what that did
I am referencing CSC from Framework (not Framework64) revision 4.0.30319
Here is the header to my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
Follow-up question (if I get this working) what things do I need to worry about to make this run on another computer? My thoughts was that all I needed was the .excel.dll and the .exe file in the same directory structure? (At this time I don't know what version of .NET or Office is being run on the target computer - my guess would be at least it would be Office 2010.)
Any guidance would be greatly appreciated. I've been wearing out google on this one for the past week+
Regards,
Keith
I know this is not the exact answer you're looking for, but I'm posting it because I think it would be more helpful than directly answering your question.
You would save yourself a LOT of time by downloading Visual C# 2010 Express and letting the IDE do the heavy lifting for you.
It sounds like you need to add a reference, which means referencing an existing .dll file somewhere. I know if can be done via the command line, but it's a LOT easier to use the IDE.
It's free, and can be found here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express
There's a How-To guide for Office Interop here: http://msdn.microsoft.com/en-us/library/dd264733.aspx
I am designing a report that will be used in local mode (an RDLC file) in a Winform app. I have a custom assembly with a static class that has some functions that I want to use inside of the report (as expressions).
I have found all sorts of help for doing this with RDL reports, but I'm running into a permissions problem with my RDLC report.
I get the following error at runtime:
"The report references the code module (my module), which is not a trusted assembly".
I know that this is some kind of a code security issue, but I'm not sure what to do to fix it. The documentation that I have seen online is aimed at RDL reports, and it instructs me to edit a SQL Server-specific policy file. I'm using RDLC, so there is no sql server involved. What do I need to do to acquire the appropriate permissions?
Try using the AddTrustedCodeModuleInCurrentAppDomain method of the
ReportViewer.LocalReport Property (reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("your assembly")).
Also make sure you use the AllowPartiallyTrustedCallers attribute with your assembly ([assembly:AllowPartiallyTrustedCallers]).
The AddTrustedCodeModuleInCurrentAppDomain method is obsolete for .Net 4.0. Visual Studio 2010 disable the call of this method. But there is the AddFullTrustModuleInSandboxAppDomain method in the LocalReport property of ReportViewer class (reportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(myAssemblyStrongName)). It requires the strong name of the assembly. My application executes fine from Visual Studio but I get the error "The report references the code module (my module), which is not a trusted assembly" when I'm manually run exe-file from folder "bin". What it can be?
#StefanHa's comment provides the answer, in case that blog post disappears here's the code that worked for me:
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
rv.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
Assembly asm = Assembly.Load("MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
AssemblyName asm_name = asm.GetName();
rv.LocalReport.AddFullTrustModuleInSandboxAppDomain(new StrongName(new StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version));
I also needed to set PermissionState.Unrestricted instead of PermissionState.None. In my example I was loading System.Web + System.Drawing and so I only needed up to the SetBasePermissionsForSandboxAppDomain.