1

I want to use HTML template in Timer Job.

My timer job is to send email.

I have the list of email address for To: List but I cannot access HTML template from the server.

I cannot use

Server.MapPath("Somepath\\test.htm")

Because its not a Http Request but a SpJobDefinition.

So how to access the file from the Server ?

PS: just like we use for FileUpload Control :

FileUpload1.SaveAs(Server.MapPath("path" + fileName));
nirav
  • 373
  • 3
  • 7
  • 20

2 Answers2

2

If your file is located in the 14 hive you can use SPUtility.GetGenericSetupPath() to get the path to your file:

SPUtility.GetGenericSetupPath("SomePath\\test.htm")

will return:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\SomePath\test.htm

in a default SharePoint setup.

Stefan
  • 14,530
  • 4
  • 55
  • 62
  • yeah... its working for 14..... Now can I do ../. [realtive path] and go to my path to access? – nirav Jan 09 '12 at 13:26
  • No, this is not meant to be used this way. However, it's best practice to deploy your files into the 14 hive with a "wsp solution". This way you ensure that the files are available on all servers in the farm. – Stefan Jan 09 '12 at 13:30
1

Also you can use Web.Config AppSetting section to read such configurations.

Here's a good example http://snahta.blogspot.com/2009/01/reading-webconfig-from-timer-job.html

Sandeep
  • 436
  • 2
  • 5