简体   繁体   English

两个应用程序读/写相同的文本文件

[英]Two apps reading/writing the same text file

I've got a Windows Service app that writes a log to a text file, and then I've got a WinForms app that needs to read the same information from the file. 我有一个Windows服务应用程序,它将日志写入文本文件,然后有一个WinForms应用程序,该应用程序需要从文件中读取相同的信息。

But how can I get both apps (in the same solution) to read/write the same file? 但是,如何在相同的解决方案中让两个应用程序读取/写入相同的文件? Both apps' use a Shared project in the same solution, but the 两个应用在相同的解决方案中使用共享项目,但是

System.AppDomain.CurrentDomain.BaseDirectory + @"\log.txt";

for both points to different directory. 两者都指向不同的目录。

For a common path, try using: 对于常见路径,请尝试使用:

string folderPath1 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
// or 
string folderPath2 = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

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

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