0 Replies - 1853 Views - Last Post: 04 April 2016 - 05:26 AM

#1 philz1982   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-April 15

Cannot get Relative Path to work in WPF Application

Posted 04 April 2016 - 05:26 AM


I am trying to get a WPF application to utilize a relative path for a word document. Admittedly I am a self-taught programmer and I have read all I can find about relative paths and I am just "missing it".

Here is what I am trying to do. I am using the DocX library to open a template word document and to replace specific anchor text with user supplied text. The new document is then saved using a build function. I cannot figure out how to reference relative locations in WPF. I have read about creating a resource but when I add the word document to a resource file that does not work.

I openly admit my ignorance in this issue and if there is something I need to read that I am missing I will gladly go to my own research I have just hit a roadblock and need a little help.

My ultimate goal is to create an installer and have this be able to be installed on our sales people's machines referencing the relative location of the documents. Right now I can create an installer but the sales people need to put the files in the hardcoded location. I could use a script to create the directory on install but that seems a bit hacky.

Please see my function that edits the template and creates the new document below:

public void CreateProposal()
            string fileNameTemplate = @"C:\X_Proposal_Tool\FinalDocs\X-Proposal-{0}-{1}.docx";
            string compName = CompName;
            string XName = XFName + " " + XLName;
            string outputFileName = string.Format(fileNameTemplate, compName, DateTime.Now.ToString("dd-MMM-yyyy"));
            DocX letter = DocX.Load(@"C:\X_Proposal_Tool\TemplateDoc\Sales_X Sample Budgetary Proposal.docx");
            DateTime dt = DateTime.Now;
            dt = dt.AddDays(Convert.ToDouble(ValidDays));
            letter.ReplaceText("[date]", dt.ToString("dd-MMM-yyyy"));
            DateTime date = DateTime.Now;           
            //Replace Financial Data
            letter.ReplaceText("[orCount]", OrCount);
            letter.ReplaceText("[sell]", Sell);
            letter.ReplaceText("[roi]", Roi);
            letter.ReplaceText("[swMaint]", SwMaint);
            letter.ReplaceText("[date]", date.ToString("dd-MMM-yyyy"));

            //Replace Customer Data
            letter.ReplaceText("[compName]", CompName);
            letter.ReplaceText("[projSiteName]", ProjSiteName);
            letter.ReplaceText("[custFName]", CustFName);
            letter.ReplaceText("[custLName]", CustLName);
            letter.ReplaceText("[compAdd1]", CustAdd1);
            letter.ReplaceText("[custCity]", CustCity);
            letter.ReplaceText("[custState]", CustState);
            letter.ReplaceText("[custZip]", CustZip);

            //Replace AE Data
            letter.ReplaceText("[xName]", XName);
            letter.ReplaceText("[XTitle]", XTitle);
            letter.ReplaceText("[brAdd1]", BrAdd1);
            letter.ReplaceText("[brCity]", BrCity);
            letter.ReplaceText("[brState]", BrState);
            letter.ReplaceText("[brZip]", BrZip);

            if (ServerNeeded)
                letter.ReplaceText("[serverNeeded]", "Furnish and install X OR Optimization Server and Network Integration Engine (NIE) " +
                    "to host the rules, provide data storage and transfer data between the BAS and the clinical application. Uninterruptable " +
                    "power shall be provided by " + CompName + " .");
                letter.ReplaceText("[serverNeeded]", "X will utilize existing server to host X OR Optimization Server and Network Integration Engine.");

            if (BalNeeded)
                letter.ReplaceText("[balNeeded]", "Provide air balance readings of OR VAV boxes before and after implementation of X to provide " +
                    "baseline of existing system performance and report of same systems performance after X implementation to verify compliance " +
                    "with design specifications and enhanced operation.");
                letter.ReplaceText("[balNeeded]", "Air Balance readings to be provide by others.");


Is This A Good Question/Topic? 0
  • +

Page 1 of 1