我正在将一个文档文件转换成一个pdf文件,但是用我当前的代码,即使在转换之后,文件似乎也是打开的。我在输出文件夹中看到pdf文件,但是如果我试图重新上传它,它告诉我它是在另一个程序中打开的(我在任何地方都看不到)。
代码节错误:
if (getExt == ".doc")
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(DocumentUNCPath.Text);
wordDocument.ExportAsFixedFormat(@"c:\temp\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
}全文方法:
private void btnSubmitStep2_Click(object sender, EventArgs e)
{
string getExt = Path.GetExtension(DocumentUNCPath.Text);
if (getExt == ".doc")
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(DocumentUNCPath.Text);
wordDocument.ExportAsFixedFormat(@"c:\temp\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
}
// Frame up the record of submission
using (var dc = new DocMgmtDataContext())
{
DocumentLibrary.Document doc = new DocumentLibrary.Document()
{
LibraryID = (AssignmentListStep2.SelectedItem as Library).ID,
OwnedByUserID = (StudentListStep2.SelectedItem as User).ID,
UploadedByUserID = (StudentListStep2.SelectedItem as User).ID,
UploadDT = DateTime.UtcNow,
ID = Guid.NewGuid()
};
dc.Documents.InsertOnSubmit(doc);
dc.SubmitChanges();
// Copy file into managed storage
doc.StoragePath = FILESTORELOCATION + doc.ID + ".pdf";
File.Copy(DocumentUNCPath.Text, doc.StoragePath);
doc.Pages = CompatiblePdfReader.VerifyAndFixPdfDocument(doc.StoragePath);
dc.SubmitChanges();
}
// Refresh the list of student submissions
UpdateStudentSubmissionGrid();
}发布于 2013-02-18 05:06:54
尝试使用wordDocument.Close SaveChanges:=wdDoNotSaveChanges关闭您的子文件末尾的文档,因为ExportAsFixedFormat不会为您关闭该文件。
https://stackoverflow.com/questions/14929657
复制相似问题