FileSystemWatcher的无法访问网络驱动器 [英] FileSystemWatcher Fails to access network drive

查看:176
本文介绍了FileSystemWatcher的无法访问网络驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行在使用Windows服务的一些服务器路径的文件守望者。
我用我的Windows登录凭据来运行服务,我能够从我的登录访问此someServerPath。
但是,当我这样做,从FileSystemWatcher的它抛出:


  

目录名称\\ someServerPath无效的异常。


  VAR fileWatcher =新FileSystemWatcher的(GetServerPath())
    {
        NotifyFilter =(NotifyFilters.LastWrite | NotifyFilters.FileName)
        EnableRaisingEvents = TRUE,
        IncludeSubdirectories =真
    };公共静态字符串GetServerPath()
{
    返回的String.Format(@\\\\ {0},FileServer1);
}

任何人都可以请帮我这个?


解决方案

我必须使用FileSystemWatcher的对象监控UNC路径没有任何问题的项目。

这是看你的code的例子可能是你在这可能不是一个有效的文件系统共享的服务器(//服务器/)的根目录共享指向看守我的猜测?我知道它返回的东西,如打印机,计划任务等,在Windows资源管理器。

尝试指向观察者的根下一个份额 - 像//服务器/ C $ /将是一个很好的测试例如,如果你在服务器上的远程管理权限

I am trying to run a file watcher over some server path using windows service. I am using my windows login credential to run the service, and am able to access this "someServerPath" from my login. But when I do that from the FileSystemWatcher it throws:

The directory name \someServerPath is invalid" exception.

var fileWatcher = new FileSystemWatcher(GetServerPath()) 
    {
        NotifyFilter=(NotifyFilters.LastWrite|NotifyFilters.FileName),
        EnableRaisingEvents=true,
        IncludeSubdirectories=true
    };

public static string GetServerPath() 
{
    return string.Format(@"\\{0}", FileServer1);              
}

Can anyone please help me with this?

解决方案

I have projects using the FileSystemWatcher object monitoring UNC paths without any issues.

My guess from looking at your code example may be that you are pointing the watcher at the root share of the server (//servername/) which may not be a valid file system share? I know it returns things like printers, scheduled tasks, etc. in windows explorer.

Try pointing the watcher to a share beneath the root - something like //servername/c$/ would be a good test example if you have remote administrative rights on the server.

这篇关于FileSystemWatcher的无法访问网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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