I
I
Ivan2020-04-14 17:39:01
WPF
Ivan, 2020-04-14 17:39:01

Why does the GetFullPath method return the wrong document path?

There is a file, the path to it is: "C:\Users\User\Desktop\Diploma - copy\Diploma\docs\zmk.docx"
In the code below, in the line

string pathToTemplateDoc = System.IO.Path.GetFullPath(@"docs\zmk.docx");

I'm trying to find this full path relative to a relative path, but the result of running this line is the string: "C:\Users\User\Desktop\Diploma - copy\Diploma\bin\Debug\docs\zmk.docx", where bin\Debug comes from ?

private void ToPrint(object sender, RoutedEventArgs e)
        {
            MainWindow window = new MainWindow();
            string[] data = window.DataCheck();

            Word.Document doc = null;
            Word.Application app = null;

            try
            {
                app = new Word.Application();
                string pathToTemplateDoc = System.IO.Path.GetFullPath(@"docs\zmk.docx");

                MessageBox.Show(pathToTemplateDoc);
                doc = app.Documents.Add(pathToTemplateDoc);
                app.Visible = true;

                Word.Bookmarks wBookmarks = doc.Bookmarks;

                foreach(Word.Bookmark mark in wBookmarks)
                {
                    if (mark.Name == "pasportSeries")
                    {
                        mark.Range.Text = pasport.Text;
                    }
                    
                }

                app = null;
                doc = null;
            }
            catch
            {
                app = null;
                doc = null;
            }
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-04-14
@Vamba45

Because when debugging, your current directory

C:\Users\User\Desktop\Диплом - копия\Диплом\bin\Debug\
, well, plus the path that you indicated to it. The file is not required at all.

I
Ivan Chikishev, 2020-04-14
@IvanChikishev

include the file in the assembly, then it will be copied to the build folder and the path to it should be available

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question