找不到此文件。 [英] This File could not be found.

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

问题描述

大家好,



我在尝试使用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");
}







有人可以帮我解决这个问题问题?



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



这里是代码...






Can someone help me to solve this issue?

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

推荐答案

不是,不。

你有一个D驱动器吗?该目录是否存在?您通过了什么值?



在该行上设置一个断点,并查看调试器中的originalFileName参数 - 您获得了什么价值?该文件是否存在?从那里开始,看看你得到了什么。
Not really, no.
Do you have a "D" drive? does the directory exist on it? What values are you passing through?

Put a breakpoint on the line, and look at the "originalFileName" parameter in the debugger - what value do you get? Does the file exist? Start there, and look at what you get.


在这里测试..我假设你想通过使用openDialog打开文件,试试这个,make textbox并命名为tbDocument以显示目录路径。



然后这里代码..

Test here.. I assume you wanna open file by using openDialog, try this, make textbox and name it "tbDocument" to show directory path.

Then here the code..
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);
        }


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆