2

In my WPF caliburn.micro application, I use ComponentOne's C1DocumentViewer to display a report.

I created in the project a new Folder “Reports” and placed the .xml there. I show the report using C1DocumentViewer. When provide the absolute path to the .xml file, it works fine. But of course I need to use a relative path. So if I make it “../../MyProject/Reports/MyReport.xml”, it works on my machine when I run it in Visual Studio. But not when I publish it using ClickOnce, it just cannot find the file. Same thing if I use “/Reports/MyReport.xml” or “Reports/MyReport.xml”. When I try to use “Reports/MyReport.xml” when I debug in Visual Studio, it is looking for the path “Reports/MyReport.xml” in bin/Debug of the main project of the solution.

Please help. Here is my code:

        protected override void OnViewLoaded(object view)
    {
        base.OnViewLoaded(view);

        var rpt = new C1.C1Report.C1Report();

        rpt.Load(@"Reports/MyReport.xml", "Recent Files Information");

        rpt.DataSource.RecordSource = "MyReportProc(1)";
        rpt.Render();
        Report = rpt.FixedDocumentSequence;
    }
David Shochet
  • 5,035
  • 11
  • 57
  • 105

1 Answers1

0

Just a guess. Your problem might be related to the working directory of your process.

When the process refers to a file using a simple file name or relative path (as opposed to a file designated by a full path from a root directory), the reference is interpreted relative to the current working directory of the process.

Check it with Directory.GetCurrentDirectory() when you run your program in Visual Studio and also when you run it after publishing it with ClickOnce.

Bill
  • 11,595
  • 6
  • 44
  • 52
  • @DavidShochet Have you checked that '../../MyProject/Reports/MyReport.xml' is a correct relative path from the working directory returned by GetCurrentDirectory() when the program is run after installed by ClickOnce? – Bill Mar 15 '13 at 13:44
  • I don't see the .xml file there at all. Looks like ClickOnce just doesn't copy it to the destination. – David Shochet Mar 15 '13 at 18:52
  • I use it like this: rpt.Load(Environment.CurrentDirectory + @"\Reports\RecentFilesInformation.xml", "Recent Files Information"); This way, the Reports folder with the .xml file is copied into bin/Debug of the main project when the solution is rebuilt, and then it works when run from Visual Studio. But when I publish it, the .xml is not found, it doesn't exist in the destination folder. I guess there may be something about the .xml file attributes that prevents it from being copied to the destination path by ClickOnce. – David Shochet Mar 15 '13 at 19:16
  • @DavidShochet Maybe the answer here: http://stackoverflow.com/questions/5605936/clickonce-file-missing can help you as well. – Bill Mar 16 '13 at 06:58
  • Thanks Bill, yes, this works when I place the report into the main project. But is it possible to add it as a link so that the project stayed not in the main project? – David Shochet Mar 18 '13 at 12:27
  • @DavidShochet I'm afraid I do not understand your question. – Bill Mar 18 '13 at 12:37