2

I got the problem that use C# process to call the LibreOffic to shift the file to ODF series. When I am in Local everything is work, but I release my project to IIS. The web site just keep running forever. Could anyone can hlep to fix this issue?

My environment: Server OS:win Server2012 IIS: version 8.0.9200.16384 I tried these LibreOffice version(Nothing is work): Fresh version(stable) 5.4.3 Stable version 5.3.7 Carry version 5.4.2.2

I think The problem is some software not Compatible. I can see the task manager has the LibreOffic.exe running

My website keep running picture can see the LibreOffice running in task manager

public class OfficeConverter
{
    /// <summary>
    /// LibreOffice通用型轉檔功能
    /// </summary>
    /// <param name="inputFilePath">The input.</param>
    /// <returns>Data為轉檔後之路徑</returns>
    [STAThread]
    public static string ConvertDocument(string inputFilePath)
    {
        // 取得副檔名對應的參數
        string extensionParameter = ConvertExtensionToArg(Path.GetExtension(inputFilePath));

        //if (string.IsNullOrWhiteSpace(extensionParameter))
        //    throw new InvalidProgramException("Unknown file type for LibreOffice. File = " + inputFilePath);

        if (!File.Exists(inputFilePath))
        {
            throw new ArgumentException(string.Format("找不到檔案:{0}!", inputFilePath), nameof(inputFilePath));
        }

        string outputDir = Path.GetDirectoryName(inputFilePath) + @"\";
        string outputFileName = Path.GetFileNameWithoutExtension(inputFilePath);
        string outputPath = string.Empty;

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;

        // 設定執行檔路徑
        startInfo.FileName = ConfigurationManager.AppSettings["LibreOfficeExePath"];
        startInfo.WorkingDirectory = outputDir;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.Arguments = string.Format(" -headless -convert-to {1} {0}", inputFilePath, extensionParameter);

        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
        string[] ext = extensionParameter.Split(':');

        outputPath = Path.Combine(outputDir, outputFileName + "." + ext[0]);

        return outputPath;
    }

    /// <summary>
    /// 依據副檔名轉換成相對應的參數
    /// </summary>
    /// <param name="inputExtension"></param>
    /// <param name="outputExtensionType"></param>
    /// <returns></returns>
    private static string ConvertExtensionToArg(string inputExtension)
    {
        switch (inputExtension)
        {
            case ".doc":
            case ".docx":           
                return "odt:writer8";
            case ".xls":
            case ".xlsx":
            case ".xlsb":               
                return "ods:calc8";
            case ".ppt":
            case ".pptx":               
                return "odp:impress8";
            default:
                return null;
        }
    }

}

I modify my code to catch Process StandardError message. But I can't catch anything. The website just still running. my BackUpLog.txt doesn't have any new message. I think that Porcess.Start() then never return any response.

This is my code I modified

12
  • You haven't provided any code? How do you expect us to troubleshoot it without the code? Please read this. When showing code to launch Libre Office I expect to see something like this Commented Dec 15, 2017 at 2:26
  • Try to capture the output of the process to see if it's spouting any error messages stackoverflow.com/a/285841/1411687
    – Alex Wiese
    Commented Dec 15, 2017 at 2:45
  • @JeremyThompson I added my code thanks. But I have one experience to release my project to another Server and it work. Using portable version. But in this server every version doesn't work. My website just keep running. I think LibreOffice doesn't give complete response to my project. But I can see the task manager has LibreOffice.exe running.
    – Leon Huang
    Commented Dec 15, 2017 at 2:46
  • What are the results if you run the LibreOffice command on the server manually? Commented Dec 15, 2017 at 2:57
  • Using Manual is work.Not use my program to run LibreOffice everything is work.
    – Leon Huang
    Commented Dec 15, 2017 at 3:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.