简体   繁体   English

如何从Windows服务读取html文件?

[英]How to read a html file from a Windows Service?

I'm trying to read a file using windows service but is giving as not found. 我正在尝试使用Windows服务读取文件,但没有找到。 As it does to read a file through my service? 可以通过我的服务读取文件吗?

string filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Email\Template.html");

string test = File.ReadAllText(filePath)

Below where the file you want to read 在您要读取的文件下方

  1. right click on Template.html -> Properties 右键单击Template.html->属性
  2. Copy to output directory -> Always Copy 复制到输出目录->始终复制
  3. and then get file path like this: 然后获取如下文件路径:

    var path = AppDomain.CurrentDomain.BaseDirectory + "email\\Template.html"; var path = AppDomain.CurrentDomain.BaseDirectory +“ email \\ Template.html”;

Make sure that " Copy To Output Directory " property is Enabled for this file. 确保为此文件启用“ 复制到输出目录 ”属性。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM