Use Office Interop on ASP.net MVC6 website - com

I want to generate word documents from my ASP.net MVC 6 website. I've implemented several ways to generate a document in a POC : DocX, NetOffice, OpenXml, COM Interop objects. I was seduced by it.
I made a Console App to test and it works.
But, with ASP.net MVC6, we can't reference Console App's or COM Assemblies.
We need to create "Console App (Package)".
How can I add COM Assemblies to my ASP.net MVC 6 website ?

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
You can read more about that in the Considerations for server-side Automation of Office article.
Consider using third-party components designed for the server-side execution or if you deal with open XML documents you may use the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.

Related

Javascript in Office

I am trying to understand how to develop add-ins/macros in JS for Office, do I need VSTO for it or does it run from Office somewhere?
I did understood that Microsoft is making the first steps toward replacing VBa with JS and impemented an API to develop macros in Office.Js simmilar to the one Google has for it's Docs. But where can I find a development enviroment for Office.js?
The new web-based add-ins are basically a web application executed in the context of the Office application, either on the Desktop (by embedding a browser, IE11 at the moment) or in the browser (Office Online) where everything is web-based already.
The add-in can be hosted on any web resource you like. You just need to specify a source location URI.
Settings and metadata of the add-in are defined in a manifest file. The article Office Add-ins platform overview describes it very well.
Development can be done in any editor or IDE suitable for coding web apps. There is no Alt+F11 VBA IDE anymore, but you may try the Script Lab add-in, a Microsoft Garage project that allows you to try out some code directly in Office and share code snippets. It includes a great collection of sample code too.
The new WebApplications are hosted on a Webserver. You can develop Office Apps with Visual Studio.
Here is a good course for developing Office Apps including an overview of the Javascript Office API:
https://mva.microsoft.com/en-us/training-courses/introduction-to-office-365-development-8329

Can one use Reportviewer Control in ASP.net Core

I want to make use of the Reporting Services ReportViewer control in an ASP.NET Core MVC project.
The solution as proposed in other answers it to add a webform to the project.
However since ASP.NET Core doesn't support webforms I cannot add the control to a webform.
Is there any other workaround that might possibly assist me in using the ReportViewer control in an ASP.NET Core Web application?
Update 2019
I have ReportViewer working on ASP.NET Core on Windows, and most features (not PDF and Images/PowerPoint) also work on ASP.NET Core on Linux.
There's still some bugs to weed out, though.
You can learn more about it in this github issue.
I can't release it publicly, because ReportViewer has a rather constricting license...
It is based on the AspNetCore.Reporting nuget by amh1979.
You might try the wrapper nuget around ReportExecution.asmx, also by amh1979, this has no licensing issues, but it's no real ReportViewer.
Original post:
No, you can't.
Microsoft is only just evaluating creating a .NET Core ReportViewer control.
Which means there isn't any at present (05/2017).
There also isn't any ReportViewer "control" for ASP.NET MVC.
There is only alanjuden's wrapper around MS-ReportServer's ReportExecution.asmx.
But that isn't the same. That will still require Windows Authentication on the report server (along with user-must-be-member-of-specific-ad-group), and a SSRS server running on Windows.
If you anyway have an SSRS-ReportServer on Windows, you're much better of embedding SSRS ReportViewer.aspx in an iframe. You might want to add forms-authentication to your reportserver. Also, if it needs to be cross-platform (=cross-browser = non-IE), you need SSRS >= 2016 (cross-browser not available in SSRS 2005/2008R1/2008R2/2012/2014).
If you're on Windows and don't want (your customer) to have to install a specific version of SSRS (which means you have to license a MS-SQL-Server), you can create a .NET non-core web application on IIS (on the same domain), and share the auth-cookie. Then you embed that ReportViewer from the IIS .NET non-core application via iframe (or link with target=_blank) in your .NET Core Web-Application. That way you don't require an SQL-Server license, and no MS-SQL-Server if you, for example, use MySQL/PostgreSQL/Oracle.
Other than wait, you can bundle Apache Tomcat with BIRT into your application, and use Launch4J to redistribute it with the JRE. Then you'll just have to use the Eclipse-BIRT ReportDesigner to create BIRT reports (non-SSRS-reports).
Or you can embed JasperReports with JasperServer.
This would be far more difficult to bin-deploy than BIRT.
But I guess docker to the rescue.
Jasper and BIRT have the advantage that they also run on Linux/Mac.
However, that means you either need the JRE installed on the server, or bin-deploy the JRE along with your application.
Jasper's advantage over BIRT is that it is faster, and that it supports vertical text (not just in the web, and vertical-text is not rendered as image).
There usually are always issues with the BIRT releases downloaded from their website that prevent running BIRT at first. Be that a missing JAVA_HOME environment variable, a missing .jar-dependency or an invalid signature in a .jar file. For information on what it will be on your machine at your time, consult the TOMCAT logfiles, and then google the problem.
The nice thing about BIRT is, that it's comparatively easy to bin-deploy.
Another option would be jsReports, if you like nodeJS.
However, Bin-Deploy that without installation and complications will be even harder (PhantomJS, Webkit, wkHtmlToPdf - for example with an ARM-processor on Raspberry PI).
If you have a few years to spare, you can also just wait until the SSRS team ports to .NET Core - if that happens at all, that is.
Here is a report viewer works on both ASP.NET MVC and ASP.NET Core.
MVC .NET Core Report Viewer

Microsoft .NET Framework 4.0 JumpList / TaskbarItemInfo example for Windows Forms

It is my understanding that JumpList implementation using Windows API Code Pack is now depreciated as Microsoft now supports JumpList directly through Microsoft .NET Framework 4.0.
http://msdn.microsoft.com/en-us/library/system.windows.shell.taskbariteminfo.aspx
I can see that it is possible to set progress etc. to the Taskbar Item in their examples; however I have struggled so much to implement this on a Windows Form.
I had successfully managed to implement JumpList and TaskBarItem progress using Windows API Pack in the past http://code.google.com/p/zscreen/source/browse/trunk/ZScreen/Forms/ZScreenConfigGUI.cs#277 but I want to move away from this dependency and utilise the Microsoft .NET Framework 4.0 instead.
Your advice is much appreciated.
Thanks
Mike
System.Windows.Application is in the presentation framework(PresentationFramework.dll) i.e. WPF. It does not exist in Winforms. So use Windows API Code Pack like here: http://code.msdn.microsoft.com/windowsdesktop/Jump-List-with-Windows-db005b99
WPF 4 provides a native support for Jump List. Instead, if we use
Windows Forms, we must adopt the Windows API Code Pack, a managed
wrapper that allows to access to the Windows API functions. Available
on NuGet too, it provides all you need to manage Jump Lists within our
Windows Forms Applications.
Another example here: http://www.codeproject.com/Articles/103913/How-to-Create-a-Custom-Jumplist-with-Custom-Events
It is my understanding that JumpList implementation using Windows API
Code Pack is now depreciated
Its not deprecated, its also a part of new .net 4 features but for WPF. For winforms, you will still have to use the pack like mentioned above.

Any tool to convert word and excel to PDF?

Is there any SDK available to convert MS word and Excel files to PDF ? I wan to do it on Web Server at run time. Im using VS 2010, .Net Framewrok 4.0
I looked into MS interop assembly but then this artical pushed me back http://support.microsoft.com/kb/257757
is there any thirdparty tool/SDK/Service available that will do that at runtime?
Check out iText, there is a Java and C# library however I think the .NET library is not free. http://www.itextpdf.com/
If you are after perfect conversion then there is no real solution available / viable other than somehow involving Office. Plain MS-Interop is a nightmare and very unreliable, but there are good third party solutions available.
Give the Muhimbi PDF Converter Services a look. It installs in your environment as a scalable and robust Windows Service and has specifically been designed for use from server based applications such as ASP.NET.
It comes with a friendly web services based interface that allows it to be used from most modern environments such as Java and .NET. It supports all common as well as some not so common file formats. Watermarking and PDF Security is included as well. If you have SharePoint in your environment then a SharePoint optimised version is available as well.
Disclaimer, I have worked on this product so the usual disclaimers apply. Having said that, it works great.
You can use the Save as function which is already available in Microsoft.Office.Interop
doc.SaveAs(ref FileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF);

Suggestions on including the web browser control in VB.Net desktop application

I am writing a desktop app in VB.Net, and I'd like to include a web browser control to automate certain functions the user might have to perform in the browser. I have to render the page so I do not want to use the webrequest to make direct calls. When I publish the app, do I have to be concerned with which version of Internet Explorer the user has on their machine? Are their any third party, freely available, stable web browser controls available for VB.Net that people are using?
You could always ignore the whole IE issue and use the Mozilla engine embedded in your app:
geckofx
"An open-source component for
embedding Mozilla Gecko (Firefox) in
.NET applications."
http://code.google.com/p/geckofx/
Several versions of Visual Studio support web browser controls. Here is an article on how to implement one.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx
The web browser control will work with different versions of Internet Explorer, but will be limited to the functionality supported by that version of Internet Explorer.
The article is based on Visual Studio 2008, but in the right corner of the article there are links, on how to use the web browser control, to earlier versions of Visual Studio.
If you embed the Webbrowser control in your application, what you're really doing is embedding a COM object. At runtime, your app will CoCreateInstance() the Webbrowser control, which will load it out of the version of SHDOCVW.DLL or IEFRAME.DLL that is currently on the machine. So, in plain English, you'll be getting the IE6, IE7 or IE8 Webbrowser control, depending on what is installed on the machine.
The practical differences, however, are minimal since the interfaces were published a long time ago and haven't changed over those versions. Differences in terms of different commands that some interfaces (such as IOleCommandTarget) support are abstracted away by the managed layer anyway, so you don't have to worry about that. The biggest difference will be rendering differences, since there is a huge delta in CSS conformance between IE6 and IE8. You'll have to test the various versions using Microsoft's app compat VHDs.
When I worked on the IE team application compatability wrt the Webbrowser control was a huge deal; the team works very hard to make sure that behavior doesn't regress for precisely this scenario—the custom enterprise VB app hosting the WebOC.
Though if you decide to go with an open-source solution to distribute with your app, may I suggest WebKit? Its layout engine is very good and the source code is pretty well maintained and easy to read, though you'll have to write your own managed hosting layer. The Gecko code is much harder to read and debug.