通过C#访问网络中的文件夹 [英] Accessing a folder in network through C#

查看:401
本文介绍了通过C#访问网络中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问netwrok的文件夹时,我得到访问被拒绝错误,

但是系统内的本地访问工作正常列出所有文件和文件夹



I get access denied error when I acces the folder which is netwrok,
However the locally accessing within the system works fine lists all the files and folders

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace IBISApplication
{
    class Program
    {
        static void Main(string[] args)
        {

          
     
            DirSearch("\\\\10.143.14.140\\D$\\nrtfiles");
            //DirSearch(@"C:\Users\U6037395\Documents\TRWork");

            Console.ReadKey();


        }

        static void DirSearch(string dir)
        {
            try
            {
                foreach (string f in Directory.GetFiles(dir))
                    Console.WriteLine(f);
                foreach (string d in Directory.GetDirectories(dir))
                {
                    Console.WriteLine(d);
                    DirSearch(d);
                }

            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

    }
}





我尝试了什么:



我试过给网络文件夹的所有权限

在我的用户名中添加了我的用户名文件夹共享权限





我收到访问被拒绝错误。



What I have tried:

I tried giving the permission has all for the network folder
Added my User name in the folder sharing permission


I am getting access denied error.

推荐答案

\\\\
rtfiles);
// DirSearch(@C:\\ \\ Users\U6037395 \Documents\TREE);

Console.ReadKey();


}

静态 void DirSearch( string dir)
{
尝试
{
foreach string f Directory.GetFiles(dir))
Console.WriteLine(f);
foreach string d in Directory.GetDirectories(dir))
{
Console.WriteLine(d);
DirSearch(d);
}

}
catch (System.Exception ex)
{
控制台。的WriteLine(ex.Message);
}
}

}
}
\\nrtfiles"); //DirSearch(@"C:\Users\U6037395\Documents\TRWork"); Console.ReadKey(); } static void DirSearch(string dir) { try { foreach (string f in Directory.GetFiles(dir)) Console.WriteLine(f); foreach (string d in Directory.GetDirectories(dir)) { Console.WriteLine(d); DirSearch(d); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } } } }





我尝试了什么:



我试过给网络文件夹的所有权限

在我的用户名中添加了我的用户名文件夹共享权限





我收到访问被拒绝错误。



What I have tried:

I tried giving the permission has all for the network folder
Added my User name in the folder sharing permission


I am getting access denied error.


你正在访问机器使用驱动器的默认管理员共享(d
You're accessing the machine using the default admin share for the drive (d


),您不太可能修改权限,因为您需要管理员才能访问它。通过适当的网络共享访问该文件夹,以便您可以控制权限,不要使用d
), it's unlikely you amended the permissions for that as you need to be admin to access it. Access the folder via a proper network share so you can control the rights, don't use "d


这篇关于通过C#访问网络中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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