简体   繁体   English

如何使用C#在远程位置创建文件夹

[英]How to create the folder in a remote place using C#

How can I create a folder and programmatically access it on a server using C#? 如何创建文件夹并使用C#在服务器上以编程方式访问它?

I have used this code: 我使用了以下代码:

string path = @"\\MyIP\C$\NEWFOLDER";

try
{
    if (!Directory.Exists(path))
    {
        Directory.CreateDirectory(path);
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

Using above code, I can create a folder on my local machine only! 使用上面的代码,我只能在本地计算机上创建一个文件夹!

When I try to create a folder on the server machine, I get this exception: 当我尝试在服务器计算机上创建文件夹时,出现以下异常:

The user name or password is incorrect 用户名或密码不正确

You need do some configurations on your server. 您需要在服务器上进行一些配置。 This is because local pc -> server need permission. 这是因为本地pc->服务器需要权限。 You need to allow IIS have the permission to create a folder on your server. 您需要允许IIS拥有在服务器上创建文件夹的权限。

It should work as long as you can access the folder from source (where your program is running). 只要您可以从源代码(运行程序的地方)访问该文件夹,它就应该起作用。 To check it, open file explorer in source machine and type \\\\targetMachineIp\\C$\\, if you can reach there and can create a folder that means only problem is in user permissions under which your program is running, try to run it under your user account. 要检查它,请在源计算机中打开文件资源管理器,然后键入\\\\ targetMachineIp \\ C $ \\,如果可以到达那里并可以创建一个文件夹,则意味着仅在运行程序的用户权限方面存在问题,请尝试在您的用户帐户。

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

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