texas697
texas697

Reputation: 6417

How to set the correct path

I need to save the pdfs in this format. *pdf-JobName--date/time. It was saving correctly when I was saving it on my localhost. I am wanting to upload it to server and needed to change the path to the directory. It is saving in the right folder but it is missing the extension. no errors are thrown

 var dt = DateTime.Now.ToString("f").Replace('/', '-').Replace(':', '-');
            var filename = string.Format(job.JobName, dt);
            string path = Path.Combine(HttpContext.Current.Server.MapPath("~/JobSetupPdfs/"), Path.GetFileName(filename));
            document.Save(path);

            // ...and start a viewer.
            Process.Start(path);

this is how it works correctly saving to localhost

  var dt = DateTime.Now.ToString("f").Replace('/', '-').Replace(':', '-');
 var filename = string.Format(@"C:\Development\TexasExterior\TexasExterior\JobSetupPdfs\{0}-- {1}.pdf", job.JobName, dt);


            document.Save(filename);

            // ...and start a viewer.
            Process.Start(filename);

Upvotes: 0

Views: 79

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239440

You don't have a format string in your second example:

var filename = string.Format(job.JobName, dt);

That line of code says to format job.JobName with the value of dt, but job.JobName has no replacement to hold the value of dt. It seems you removed the format string of the first example thinking that the whole thing was for local only. Most likely you need something like:

var filename = string.Format("{0}--{1}.pdf", job.JobName, dt)

Upvotes: 1

Related Questions