如何使用C#在远程位置创建文件夹 [英] How to create the folder in remote place using C#

查看:381
本文介绍了如何使用C#在远程位置创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#以编程方式在服务器中创建文件夹和访问权限



我使用过此代码:



How can I create a folder and access in server programmatically using 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);
}





我的尝试:



使用上面的代码,我只能在我的本地机器上创建一个文件夹!

当我尝试在服务器机器上创建一个文件夹时,我得到了例外



用户名或密码不正确



谢谢。



What I have tried:

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 exception

The user name or password is incorrect

Thank you.

推荐答案

\ NEWWFOLDER;

尝试
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
\NEWFOLDER"; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } catch (Exception ex) { MessageBox.Show(ex.Message); }





我尝试过:



使用上面的代码,我可以创建一个文件夹只在我的本地机器上!

当我尝试在服务器机器上创建一个文件夹时,我得到例外



用户名或密码是不完整的rrect



谢谢。



What I have tried:

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 exception

The user name or password is incorrect

Thank you.


你不能只访问网络上的任何机器并创建文件或目录等等你可以在未经我许可的情况下进入我的房屋并重新安排家具。

要搬家里的椅子你需要钥匙到我的前门(或后门) - 没有你没有得到in!

使用远程PC,它是相同的:除非您使用有效的用户名和密码组合登录远程PC,否则不会影响硬盘驱动器内容。对于这样的路径,您需要成为远程PC上的管理员,因为出于安全原因,这些天改变启动驱动器的根文件夹是不受欢迎的。

通常,您会给出名称远程机器上的共享文件夹,以便访问它,或者你没有进入 - 并且共享根是一件危险的事情,所以不要指望有太多人这样做!

你可能想要使用 ConnectionOptions类 [ ^ ]提供远程机器的登录详细信息。
You can't just access any machine on your network and create files or directories, and more than the you can access my home without my permission and rearrange the furniture.
To move the chairs in my house you need the key to my front (or back) door - without that you aren't getting in!
With a remote PC, it's the same: unless you can log into the remote PC with a valid username and password combination, you can't affect the hard drive content. And for a path like that, you need to be an admin on the remote PC as changing the root folder of a boot drive is frowned upon these days for security reasons.
Normally, you would give the name of a shared folder on the remote machine in order to access it, or you aren't getting in anyway - and sharing the root is a dangerous thing, so don't expect too many people to do it!
And you probably want to use the ConnectionOptions class[^] to provide the login details for the remote machine.


这篇关于如何使用C#在远程位置创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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