In this i am trying to convert word to pdf file. But i am getting an error "The process cannot access the file because it is being used by another process".
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;
}
Is there anything missing in my code while converting? Can anyone tell me how to convert word to pdf.