在此我試圖將word轉換爲pdf文件。但我得到一個錯誤 「該進程無法訪問該文件,因爲它正在被另一個進程使用」。錯誤進程無法訪問該文件,因爲它正在被另一個進程使用
public Microsoft.Office.Interop.Word.Document wordDocuments { get; set; }
Microsoft.Office.Interop.Word.Application apword = new Microsoft.Office.Interop.Word.Application();
try
{
if (uploadFInput.HasFile)
{
targetPathip = Server.MapPath(Path.GetFileName(uploadFInput.PostedFile.FileName));
if (File.Exists(targetPathip))
{
File.Delete(targetPathip);
}
string Extentsion_path = Path.GetExtension(targetPathip);
string Filename_path = Path.GetFileName(targetPathip);
if (Extentsion_path == ".doc" || Extentsion_path == ".docx")
{
uploadFInput.SaveAs(targetPathip);
LblFleip.Text = targetPathip;
//wordDocuments = apword.Documents.Open(Filename_path);
wordDocuments = apword.Documents.Open(Filename_path);
// wordDocuments = apword.Documents.Open(targetPathip);
wordDocuments.ExportAsFixedFormat(Filename_path, WdExportFormat.wdExportFormatPDF);
apword.Documents.Close(Filename_path);
}
string filename = Path.GetFileName(targetPathip);
uploadFInput.SaveAs(targetPathip);
LblFleip.Text = targetPathip;
}
}
catch (Exception ex)
{
apword = null;
return;
}
轉換時我的代碼中是否有缺失?任何人都可以告訴我如何將word轉換爲pdf。
'wordDocuments = apword.Documents.Open(Filename_path).. wordDocuments.ExportAsFixedFormat(Filename_path,X)' - 相同的文件名*非常*可疑。 – user2246674
@ user2246674它曾在Windows窗體中工作過相同的代碼.... – pdp
當您運行此代碼時,實際的Word文檔不會在您的桌面上打開嗎? –