通过win服务在局域网其它机器上,创建目录出现System.UnauthorizedAccessException异常 通过win服务创建目录出现错误
System.UnauthorizedAccessException: 对路径“\\192.168.1.5\download\”的访问被拒绝。
同样代码,在asp.net 和 winform 程序中,测试没有问题,目录权限都加上了.
try
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
//判断文件夹否存在,不存在则创建
if (!dir.Exists)
{
dir.Create();
} using (FileStream fs = new FileStream(path + filename, FileMode.Create, FileAccess.Write, FileShare.Write))
{
using (StreamWriter stw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("utf-8")))//HttpContext.Current.Response.ContentEncoding(aspx)
{
stw.Write(content);
}
}
}
catch (Exception ex)
{
throw ex;
}
System.UnauthorizedAccessException: 对路径“\\192.168.1.5\download\”的访问被拒绝。
同样代码,在asp.net 和 winform 程序中,测试没有问题,目录权限都加上了.
try
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
//判断文件夹否存在,不存在则创建
if (!dir.Exists)
{
dir.Create();
} using (FileStream fs = new FileStream(path + filename, FileMode.Create, FileAccess.Write, FileShare.Write))
{
using (StreamWriter stw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("utf-8")))//HttpContext.Current.Response.ContentEncoding(aspx)
{
stw.Write(content);
}
}
}
catch (Exception ex)
{
throw ex;
}
在服务运行的系统和文件存储服务器的系统中新建以 filestorage 为用户名, 123456为密码的帐号,并赋予相应的权限。2.
文件存储服务器上设置好了帐号之后,在新建一个sharebing并赋予filestorage帐号的权限
3.
设置服务运行的帐号为filestorage这个账号4.
最后此服务就可以通过\\serverName(IP)\shareName\.. 来访问共享出来的文件夹了。
http://topic.csdn.net/u/20080421/22/4c2c8a27-d914-4c3c-bf26-229ecca3e34f.htmlhttp://topic.csdn.net/u/20090109/10/70305f2d-f7ad-4b0b-b269-bb872f4d3a94.html...