入门装配中的当前目录使用的Web服务应用程序和窗口服务 [英] Getting the current directory in an assembly used by a web service app and windows service

查看:63
本文介绍了入门装配中的当前目录使用的Web服务应用程序和窗口服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有读取配置文件,该文件是在应用程序目录中的程序集。

I have an assembly that reads a configuration file which is in the application directory.

该组件由Windows服务和Web服务使用。

This assembly is used from a windows service and a web service.

从Windows服务以下工作:

From the windows service the following works:

字符串通过ConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,MyFile的的.config);

string ConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyFile.config");

不过从WebService,baseDirectory就是配置文件是bin目录之前所在的目录

However from the webservice, baseDirectory is the directory before the bin directory where the config file is.

那么,如何使装配找到既是一个Windows服务和Web服务的文件?

So how do I make the assembly find the file for both a windows service and a web service?

由于
JD。

Thanks JD.

推荐答案

为什么你不只是检查,如果配置文件中的

Why do you not just check if the config file exists in


Path.Combine(AppDomain.CurrentDomain.BaseDirectoryMyFile.config);

和如果没有你点击这里:

and if it does not you check here:


Path.Combine(AppDomain.CurrentDomain.BaseDirectorybin\MyFile.config);

希望我理解行为的描述中的Web服务案正确。

Hopefully I understood the description of the behaviour in the "webservice case" correctly.

这篇关于入门装配中的当前目录使用的Web服务应用程序和窗口服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆