在此我试图将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文档不会在您的桌面上打开吗? –