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
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.