1

I'm using dotnet-mammoth (mammoth.js with edge.js) to convert a docx document to html in .net
I added it to my project via its nuget package.

I'm using the code provided by the sample, which is working correctly in my development enviroment (running IIS Express):

var documentConverter = new Mammoth.DocumentConverter();
var result = documentConverter.ConvertToHtml(Server.MapPath("~/files/document.docx")); // problem here at production enviroment
string theResult = result.Value

However, once I deploy it to production server, when the executed code reaches documentConverter.ConvertToHtml() method, it's redirecting me to the login page. Without displaying any error messages, without saving anything on IIS log file.

If I remove that line, everything else executes normally. I assume it could be an issue related to permissions but I don't know what could it be. Any ideas?

zed
  • 2,106
  • 4
  • 23
  • 40

2 Answers2

2

The latest version of Mammoth on NuGet no longer uses edge.js, and is now just .NET code, so should work more reliably.

Philip Kirkbride
  • 17,347
  • 30
  • 101
  • 195
Michael Williamson
  • 10,740
  • 4
  • 33
  • 32
  • I've updated Mammoth to the latest version as suggested, and it works excelent! I'm accepting this as answer (it does not exactly answer the initial question, but I haven't received any other helpful answers, and this actually circumvent the problem). Thanks! – zed May 14 '16 at 15:20
0

You can resolve this by getting the exact error when the process is trying to read the file. Below is the code from dotnet-mammoth DocumentConverter.cs. As shown below on call it is trying to read all bytes to be sent to edge

public Result<string> ConvertToHtml(string path)
        {
            var mammothJs = ReadResource("Mammoth.mammoth.browser.js") + ReadResource("Mammoth.mammoth.edge.js");

            var f = Edge.Func(mammothJs);
            var result = f(File.ReadAllBytes(path));
            Task.WaitAll(result);

            return ReadResult(result.Result);
        }

I suppose you are giving absolute path to the input. In that case the absolute path should be accessible by app identity hosting the app pool of the web application.

If the path specified is in web root directory - (not advised) - but if it is then you can use Server.MapPath

Community
  • 1
  • 1
lazy
  • 533
  • 2
  • 4
  • I use `Server.MapPath` (see updated code) to a subfolder. I have permissions to that folder because lines before I'm uploading that very same file successfuly (I removed the upload part of code because it is working fine). – zed Sep 02 '15 at 11:17