本文介绍了找不到此文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在尝试使用word文件进行操作时出现以下错误。



找不到此文件。 (C:\ // Users / rahul raj / AppData / Loc ......)



以下代码导致异常.. 。

Hi All,

I have got the following error when I was trying to do some operations with a word file.

This File could not be found. (C:\//Users/rahul raj/AppData/Loc......).

The following code caused exception...

textBox1.Text = @"C:/Users/rahul raj/AppData/Local/Temp/ConsultantResumes/PROGRAMMER_NAVEEN.doc";
textBox2.Text = @"E:\Ace Logic\Consultrak\Resumes\PROGRAMMER_NAVEEN.doc";

Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

object originalFileName = textBox1.Text;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object destinationName = textBox2.Text ;

try
{
    Microsoft.Office.Interop.Word.Document openDocument = WordApp.Documents.Open(ref originalFileName, ref missing, ref readOnly,
                                                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                                    ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
    openDocument.SaveAs(ref destinationName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

    ((Microsoft.Office.Interop.Word._Document)openDocument).Close(ref missing, ref missing, ref missing);
    ((Microsoft.Office.Interop.Word._Application)WordApp).Quit(ref missing, ref missing, ref missing);

    System.Windows.Forms.MessageBox.Show("Finished", "AddTo - Test");
}
catch (Exception Ex)
{
    System.Windows.Forms.MessageBox.Show(Ex.Message.ToString(), "AddTo - Test");
}











我已经解决了这个问题,只需更改/



这里是代码...








I have solved this problem by simply changing /

here is the code...

if (textBox1.Text.ToString().Contains("/"))
            {
                textBox1.Text = textBox1.Text.Replace("/", "\\");
            }





问候

Sebastian



Regards
Sebastian

推荐答案


private void readFile()
        {
            try
            {
                //OpenFileDialog openDialog = new OpenFileDialog();
                openDialog.DefaultExt = ".doc";
                openDialog.Filter = "Word Documents|*.doc|Text Files|*.txt";
                openDialog.FileName = string.Empty;
                openDialog.ShowDialog();
                tbDocument.Text = openDialog.FileName;

                if (tbDocument.Text.Length > 0)
                {
                    readFileContent(tbDocument.Text);
                    currentFile = openDialog.FileName;
                    //rtbInput.Modified = false;
                }
                else
                {
                    MessageBox.Show("Enter a valid file path");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error");
            }
        }


private void readFileContent(string path)
        {
            Microsoft.Office.Interop.Word.ApplicationClass wordAppClass = new ApplicationClass();
            object file = path;
            object nullobj = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word.Document wordDoc = wordAppClass.Documents.Open(
                ref file, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj);
            wordDoc.ActiveWindow.Selection.WholeStory();
            wordDoc.ActiveWindow.Selection.Copy();
            IDataObject data = Clipboard.GetDataObject();
            rtbInput.Text = data.GetData(DataFormats.Text).ToString();
            //wordDoc.Close(ref nullobj, ref nullobj, ref nullobj);
            wordAppClass.Quit(ref nullobj, ref nullobj, ref nullobj);
        }


这篇关于找不到此文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:25