I am using Quartz.Net in Asp.Net C# to schedule my task. I want to write to a file, when I try without the MapPath
it's writing to the file as expected (Hello world).
Here is the code what I wrote. I have tried HostingEnvironment.MapPath
and Server.MapPath
. It's simply writing the file without any content.
public void Execute(IJobExecutionContext context)
{
StreamWriter file = new StreamWriter("destination_actualPath\\hello1.txt", true);
file.WriteLine("Hello world " + Server.MapPath("../Data"));
file.Close();
}
Yes this folder Data
do exist in my project directory. This function is inside the IJob
class. If I write a new method (other than execute) it's writing to the file (hello world and path), it's not writing any content to the file if it's inside this Execute
method.
try
file2.WriteLine("Hello World " + System.Web.Hosting.HostingEnvironment.MapPath("~/Data"));
HttpContext
is not allowed in Quartz.net, so we have to use HostingEnvironment
instead. Here we usually refer virtual path using ~
, not ../
. I guess this is your mistake.