在远程服务器中创建文件夹时出错
您好,我有一个编写的代码,用于在 .net 的远程服务器中写入文件。当我将输出路径保留为本地驱动器时 - 代码工作正常并创建文件夹和文本文件。但是当我指向远程服务器时,出现以下错误:
System.UnauthorizedAccessException: Access to the path '\\ServerName\FolderTest\FolderTest1\AB.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at ...
如果您需要其他信息,请告诉我
Hi I have a written for code for writing a file in the remote server in .net. When I keep output path as local drive - the code works fine and creates folders and text files. But when I point to a remote server, I get below error:
System.UnauthorizedAccessException: Access to the path '\\ServerName\FolderTest\FolderTest1\AB.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at ...
If you need additional information let me know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在什么环境中执行代码? Winforms、Web 表单还是 win 服务?
对于所有这些情况,有不同的方法可以解决此问题:
模拟
,则在您的帐户下执行,因此该帐户必须具有远程服务器上 creatinf 文件夹的权限。In which environment do you execute your code? Winforms, web forms or win services?
For all this cases, there are different wways to solve this issue:
impersonation
, so this accounts must have the permissions for the creatinf folder on a remote server.您可能需要为要保存文件的文件夹的正确用户设置权限。
这篇文章可能会为您提供答案:
链接 - System.UnauthorizedAccessException
You probably need to set the permisions to the right user on the folder where you want to save the file.
This post might have the answer for you:
Link - System.UnauthorizedAccessException
代码现在可以正常工作了。问题是访问权限。我的代码写入该文件夹的凭据未添加到文件夹安全选项卡中。添加后就可以了。它起作用了。谢谢@James Deville、@VMAtm 和@Razvan Panda :)
The code worked properly now. The issue was the access permission. The credential with my code wrote to the folder was not added to the folder security tab. After adding to it. It worked. Thanks @James Deville, @VMAtm and @Razvan Panda :)