Answer the question
In order to leave comments, you need to log in
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");
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
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.
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 questionAsk a Question
731 491 924 answers to any question