I try open .doc file with interop, when I debug code in Visual studio result is a file but I publish web to IIS result is null.
I'm using Windows server 2012 64bit and Microsoft Office 2007.
Why result in IIS return null and solution?
var wordApp = new Application { Visible = false };
var path = Request.PhysicalApplicationPath + "File\\TestFile.doc";
object srcPath = path;
var wordDoc = wordApp.Documents.Open(ref srcPath);
When you execute the program from the Visual studio then code uses the logged in user to make calls for COM components(Microsoft word). Generally logged in user has permission to execute the calls on the COM component. So code will work in the Visual studio.
When you publish the website into IIS then it uses default user of IIS to make the call to COM component. If that user doesn't have the permission then call fails and throws the exception.
First find out the user that IIS is using. Add that user to the specific COM component and give the permission to execute the calls.
Start > Run > dcomcnfg
Navigate to Component Services > Computers > My Computer > DCOM Config
Locate to "Microsoft Word 97 – 2003 Document" > Right click > Properties
On the security tab: Select all radio to (Use default)
Related
We are using ironPDF to genetate PDF file from HTML string. It is a MVC web application written in C# (.net framework 4.8) , deployed to IIS
I did the following.
Added IronPdf nuget package to the project (Version: 2022.11.10347)
Use the following code to generate PDF from string
using IronPdf; (on top of the code to add ref)
PDF generation code as below;
public ActionResult ExportPDF()
{
var Renderer = new IronPdf.ChromePdfRenderer();
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
return File(pdfDoc.Stream.ToArray(), "application/pdf", "TransactionStatement.pdf");
}
here htmlstring is the html that need to be rendered to PDF
This code works fine and generates PDF when I run in my local dev machine.
But when I deploy this code to our integration environment , it is failing. It is not generating any PDF.
It just hangs for couple of minutes then our website is getting timed out and application pool is getting stopped.
the failure is happening is in the following line
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
Out integration environment is in IIS (Windows server 2008 R2) . and application pool identity is NetworkService.
When I looked into the event log I can see the following warnings
Application popup: IronCefSubprocess.exe - System Error : The program can't start because api-ms-win-core-com-l1-1-0.dll is missing. from your computer. Try reinstalling the program to fix this problem.
A process serving application pool '<poolname>' suffered a fatal communication error with the Windows Process Activation Service. The process id was '5940'. The data field contains the error number.
I have all required Visual C++ redistributables installed in my server as described in the ironPDF website
Any idea how to fix this issue.
For API-MS-WIN-CORE-COM-L1-1-0.DLL. You could refer to this to reinstall API-MS-WIN-CORE-COM-L1-1-0.DLL.
About application pool error. As the community member said, need configuration information is needed to locate the cause.
In my opinion, you could try turn Enable 32-bit applications to true. If still don't work, you can refer to this using debugging tools to locate the cause.
I have a project in visual studio written in C# that uses ABCpdf to create a PDF page count. I set the install to be instanced as the project is deployed on a server and the project is run without admin rights as our IT department does not want to have a GMSA with admin privs to run it (it runs as a nightly windows task schedule). My issue is the application fails when it tries to generate the PDF due to access denied when installing the license. If I run the application as administrator on the server it runs fine, so it's definitely something to do with no admin rights when installing the license (or other aspects perhaps to run).
My code for installing looks like this:
try { string sResult;
if (WebSupergoo.ABCpdf11.XSettings.InstallRedistributionLicense("<license string>"))
{
sResult = "License Installed Successfully: " + WebSupergoo.ABCpdf11.XSettings.LicenseDescription;
}
else
{
sResult = "License Installation Failed";
}
<does other formatting things for the pdf creation after this in the try catch>
Does anyone know how to get this working without admin rights, or do you know the specific task or registry item it modifies so I can give the GMSA access just to that without full privs? Any help would be awesome. Thanks in advance!
I try convert Office documents using Office.Interop running under separate Windows service.
This service is running under specific account (username in future).
All folder access rights is set for this account. And when i try to create any of Office application (for example, var app=new Excel.Application()) then my code fails with exception:
Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: E_ACCESSDENIED.
Ok, but i have already configured the DCOM permissions for this CLSID! I open the dcomcnfg.exe , select component with this CLSID, opening settings, security and see that user of this service have all rights for this component.
Why this exception throws?
Ocka guys, i found the answer.
1) Be sure that you have install a right version of Office 2007
2) Be sure that you have install a PDF\XPS addin
3) Just office and its addin installed, you should run DCOMCNFG and pick My Computer->DCOM config. As it turned out, after office installation there is no mappings between CLSID and AppID in registry.
4) Close dcomcnfg window. Now there is right mappings in registry. You should get all things related to office (its id, e.g. {XXXXXXX-XXXX...}) in HKCR\AppID and HKCR\CLSID
5) For all these id's you should grant access, this can be achieved using this algorythm:
* open HKCR\AppID{id} key
* setup LaunchPermission and ActivatePermission values (code to do this find there in stackoverflow)
* Set value "RunAs" as "Interactive User"
Ocka, your office automation should work correctly, if i didn't forget some step..
I have a c# console application running daily as a scheduled task.
Recently I've added a new functionality to send an e-mail with an attached pdf report, using Access 2010 built-in pdf export:
using MsAccess = Microsoft.Office.Interop.Access;
//(...)
AccApp = new MsAccess.Application();
AccApp.Visible = false;
AccApp.OpenCurrentDatabase(DBPathname, false);
AccApp.DoCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport, "GMB_CSS_Report", "PDFFormat(*.pdf)", ReportFilename, false, Type.Missing, Type.Missing, MsAccess.AcExportQuality.acExportQualityPrint);
//(...)
When I run the new version interactively on the command line it works well, exporting the report as a PDF to the designated path\file.
But when I run it from task manager, using the same credentials, it crashes on the DoCmd.OutputTo(...) statement with the error:
(System.Runtime.InteropServices.COMException) Microsoft Access can't save the output data to the file you've selected.
That does not make any sense, as the application successfuly writes several other files to the same folder, running either from the console or from the task manager.
I've also found that the application runs without the error as a scheduled task on a third PC, not integrated in the company AD domain (the production and dev hosts are on the domain), even though all 3 hosts have the same s/w level (Win7 SP1, Access 2010 updated to latest patches via Windows Update).
This is bizarre... am I missing something here ? Any suggestions will be greatly appreciated.
Thanks in advance.
I think that your problem is in the "PDFFormat(*.pdf)" constant string.
The right one for PDF is this:
public const string acFormatPDF = "PDF Format (*.pdf)";
And this is for RTF:
public const string acFormatRTF = "Rich Text Format (*.rtf)";
I still have got problems with the same function on a 64Bit version of Access 2010 running on Windows 2008 Server 64Bit, while it works perfectly on a Windows Server 2003 machine 32bit with Access 2010 32bit.
I am using Microsoft Office Excel Interop to create an excel file in ASP.NET C#. Everything is successful when I am running application in Visual Studio 2010. I have published my web application in my own IIS server, it is ok. But when I publish application in Windows Server 2008, the problem was detected.
I looked for much in internet and i have done following, but the problem still was not solved:
I have set Application Pool Identity to LocalSystem. In Run -> mmc -32 -> Component Services -> My Computer -> DCOM Config -> Microsoft Excel Application -> right-click -> Properties window: in Identity tab, I have checked all radio buttons in this window.
I have set Application Pool Identity to NetworkService, and I have checked all previous radio buttons again.
In Run->mmc -32 -> Component Services -> My Computer -> DCOM Config -> Microsoft Excel Application -> right-click -> Properties window: in Security tab: I gave Local Launch and Local Activation for INTERACTIVE, NETWORK SERVICE, IIS_IUSRS users.
Here is my code which I used Interop Excel:
Excel.Application xlApp = new Excel.Application();
object misValue = System.Reflection.Missing.Value;
Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(misValue);
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Workbook.SaveAs(Server.MapPath("DownloadFolder\\" + fileName + "_siyahi.xls"));
I found my problem. In my Windows Server system regional settings haven't been United States and I have set worksheet.cells.NumberForm="0.00" in my code.
xlWorkSheet.Cells[rowNumber, 4].NumberFormat = "0.00";
Server doesn't knows this number format. I have changed Format to English (United States) and Current location to United States and my problem solved.