2

i'm trying to convert a .doc | .docx file into .pdf but the conversion is happening but i get this popup box is there anyway to avoid this

enter image description here here is my code Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document wordDoc = wordapp.Documents.Open(@"C:\inetpub\wwwroot\WebSite1\temp\random.docx"); wordDoc.Protect(Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection); wordDoc.ExportAsFixedFormat(@"C:\inetpub\wwwroot\WebSite1\temp\random.pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF,false);

Thanks all

DannyBoi
  • 636
  • 1
  • 7
  • 23
  • If I'm correct you only get this dialog if you have opened a file over webdav, is that the case? The code you're showing, does that run in a web application or in a win/wpf/console app? – rene Feb 24 '16 at 09:22
  • @rene it is running in a web service – mayur manudhanya Feb 24 '16 at 09:34
  • You really shouldn't use office interop from a webservice. You will have tons of problems down the line with memory/resource leaks as well as user interaction issues such as what you are currently running into. – Matthew Whited Feb 24 '16 at 15:47
  • Possible duplicate of [Export Doc to PDF Asp.net](http://stackoverflow.com/questions/17369539/export-doc-to-pdf-asp-net) – Matthew Whited Feb 24 '16 at 15:48

1 Answers1

6

You should forcibly open the word document as read-only...

Microsoft.Office.Interop.Word.Document wordDoc = wordapp.Documents.Open(@"C:\inetpub\wwwroot\WebSite1\temp\random.docx", ReadOnly:true);

See https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.documents.open.aspx for other options that you may find additionally useful (such as not adding file to the recently used list)

Kev
  • 1,832
  • 1
  • 19
  • 24