2013-02-18 2 views
0

doc 파일을 pdf 파일로 변환하고 있지만 현재 코드를 사용하면 변환 후에도 파일이 열려있는 것처럼 보입니다. 출력 폴더에있는 pdf 파일을 볼 수 있지만 재 업로드하려고하면 다른 프로그램에서 열립니다 (어느 곳에서도 볼 수 없음).doc 파일을 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(); 
} 

답변

0

가 파일을 닫습니다하지 않습니다 ExportAsFixedFormat로, wordDocument.Close SaveChanges:=wdDoNotSaveChanges와 하위의 끝에서 문서를 닫으십시오 당신.

+0

감사합니다. 나는 이것을 시도해 볼 것입니다. 하지만 내가 확장 기능을 점검하거나'UpdateStudentSubmissionGrid(); '문 앞에 ur 제안을 입력해야합니까? – BB987

+1

더 이상 문서라는 단어를 사용하지 않는 첫 번째 지점에서. 나는 ExportAsFixedFormat 호출 바로 다음에 제안 할 것이다. 'wordDocument.Close SaveChanges : = wdDoNotSaveChanges' – AerusDar