Forum How do I...?

SetBaseURL dropping last directory?

apfisterer
I'm trying to read images locally using the file:// protocol. It works but with one oddity. I'm wondering if this is a known issue.

Here is my C# code:

            var p = new Prince(@"C:\Utils\PrinceEngine\bin\Prince.exe");
            p.SetLog(@"C:\_temp\PrinceTempFiles\princelog.txt");
            p.SetHTML(true);

            // this works
            p.SetBaseURL(@"file://C:/Images/Images/");
            // this does not
            //p.SetBaseURL(@"file://C:/Images/");

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.LoadXml("<html><head></head><body><h1>Image here</h1><img src='Medical/n1404.jpg' /></body></html>");

            FileStream outFile = new FileStream(@"C:\_temp\PrinceTempFiles\outfile.pdf", FileMode.Create);

            if (p.ConvertString(doc.OuterXml, outFile) == true)
            {
                outFile.Flush();
                outFile.Close();
                System.Diagnostics.Process.Start(@"C:\_temp\PrinceTempFiles\outfile.pdf");
            }


My image is located in C:\Images\Medical.

Note the comments around SetBaseURL:

// this works
p.SetBaseURL(@"file://C:/Images/Images/");
// this does not
//p.SetBaseURL(@"file://C:/Images/");

Furthermore, for the one I would expect to work where I set the base URL to C:\Images I get this in the log file:

Fri Aug 6 07:47:50 2010: C:\Medical\n1404.jpg: warning: can't open input file: No such file or directory

It seems to be dropping the last directory passed into SetBaseURL. Removing the trailing slash makes no difference.

So, I can work around this but am I doing something wrong?

thx...Adrian.
mikeday
The base URL is the notional URL of the document itself, not its parent directory. This is similar to the way the HTML <base> element works, and the xml:base attribute.