C# Word到PDf转换的PDf有错误-拒绝访问错误

C# Word到PDf转换的PDf有错误-拒绝访问错误,c#,pdf,ms-word,itextsharp,C#,Pdf,Ms Word,Itextsharp,将MS word文档转换为PDF后。如果我发送相同路径的已转换word到pdf。i、 e PDF。在提取文件时,在服务器上发布网站时,我会遇到访问被拒绝的错误。它在本地计算机上工作。是否有我在代码中留下的东西,或者是否有我需要安装的东西 public string WordtoPdf_Input(string wordFileName_input) { try { Microsoft.Office.Interop.Word.A

将MS word文档转换为PDF后。如果我发送相同路径的已转换word到pdf。i、 e PDF。在提取文件时,在服务器上发布网站时,我会遇到访问被拒绝的错误。它在本地计算机上工作。是否有我在代码中留下的东西,或者是否有我需要安装的东西

 public string WordtoPdf_Input(string wordFileName_input)
    {

        try
        {

            Microsoft.Office.Interop.Word.Application appWord_input = new Microsoft.Office.Interop.Word.Application();
            object _MissingValue_ip = System.Reflection.Missing.Value;
            //filename_doc = System.IO.Path.GetFileName(LblFleip.Text);
            //wordFileName = LblFleip.Text;
            string pdfFileName = string.Empty;
            appWord_input.Visible = false;
            appWord_input.ScreenUpdating = false;

            // Cast as Object for word Open method
            object filename = (object)wordFileName_input;

            // Use the dummy value as a placeholder for optional arguments
            Microsoft.Office.Interop.Word.Document doc = appWord_input.Documents.Open(ref filename, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
            doc.Activate();

            InputFilename = pdfFileName = Path.ChangeExtension(wordFileName_input, ".pdf");
            object fileFormat = WdSaveFormat.wdFormatPDF;

            //All is well until here, Save thinks the excelfile is readonly
            object tmpName = Path.GetTempFileName();

            File.Delete(tmpName.ToString());

            // Save document into PDF Format
            doc.SaveAs(ref tmpName,
             ref fileFormat, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);

            // Close the Word document, but leave the Word application open.
            // doc has to be cast to type _Document so that it will find the
            // correct Close method.    

            object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
            ((_Document)doc).Close(ref saveChanges, ref _MissingValue_ip, ref _MissingValue_ip);
            doc = null;

            // word has to be cast to type _Application so that it will find
            // the correct Quit method.
            ((_Application)appWord_input).Quit(ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
            appWord_input = null;


            File.Delete(InputFilename.ToString());

            File.Move(tmpName.ToString(), InputFilename.ToString());
            //File.Move(tmpName,InputFilename.ToString())
            filePath_input = InputFilename.ToString();


            GC.Collect();
            GC.WaitForPendingFinalizers();

        }


        catch (Exception ex)
        {

        }
        finally
        {
            GC.Collect();  // force final cleanup!
            GC.WaitForPendingFinalizers();
        }
        return filePath_input;
    }

Public void PDFnumofPagecount()
{
 LblFleip.Text = filePath_input;





                PdfReader readerPages_ip = new PdfReader(LblFleip.Text);
  NumberofPages_ip = readerPages_ip.NumberOfPages;
                txtbNumberofPages_ip.Text = NumberofPages_ip.ToString();
                readerPages_ip.Close();

}

i have used itextsharp for reading pages and extraction of PDF

您是否检查了用户在发出错误的机器上的权限(以确保他们具有所需的读/写权限)?

您可以发布异常的stacktrace吗?我不明白为什么这个答案被否决。我对它投了更高的票,因为这是一个很好的反问(但也许它应该被添加为一个评论)。我很确定“拒绝访问”警告与权限有关。文件被锁定,或者Web服务器以无法访问该文件的用户身份运行。谢谢Bruno.:)我想发表评论,但由于没有足够的声誉,无法发表评论!所以,我不得不这样做作为一个答案…我已经改变了服务器。以同样的权限,现在它的工作良好。在一个或多个服务器中具有相同权限,但它不工作。