无法共享本地文件夹

问题1: 本地文件夹单击右键弹出的菜单没有“共享和安全...”项,无法共享。

解决:菜单 工具 -> 文件夹选项 ->  “查看”页 -> 选择“使用简单共享(推荐)”->  确定

 

问题2:已经能够进入“共享和安全...”项,但“共享”页面上所有项目都是灰色不可用(“在网络上共享这个文件夹”复选框不可用)

解决: 启动Server服务。开始->  运行->  输入services.msc->  在服务列表查找到Server服务 -> 设置为手动并启动

 

问题3:在服务列表没有发现Server服务

解决: 在本地连接属性里添加“Microsoft网络的文件和打印机共享”。

开始 -> 设置->  网络连接->  本地连接 -> 单击“属性”->  单击“安装”->  选择“服务”,单击“添加”->   选择网络服务列表中的“Microsoft网络的文件和打印机共享”,单击“确定”

 

问题4:在“本地连接 属性”的“此连接使用下列项目”列表发现已经安装了“Microsoft网络的文件和打印机共享”。

解决:先卸载该该项目,再按照问题3的解决方法添加该项目。

 

实际情况下可能遇不到这么多问题,否则要解决第一个问题,必须要先解决问题2,3,4

你可以使用C#中的System.IO和System.Net命名空间来实现复制本地文件夹共享文件夹的功能。以下是实现的基本步骤: 1. 使用Directory.GetFiles和Directory.GetDirectories方法获取本地文件夹中的文件和子文件夹。 2. 使用File.Copy方法将文件从本地文件夹复制到共享文件夹。 3. 使用Directory.CreateDirectory方法在共享文件夹中创建子文件夹。 4. 递归调用自己,将子文件夹中的文件和文件夹复制到共享文件夹中。 以下是一个示例代码,可以将本地文件夹D:\LocalFolder复制到共享文件夹\\Server\SharedFolder: ```csharp using System.IO; using System.Net; public void CopyFolderToSharedFolder() { string localFolderPath = @"D:\LocalFolder"; string sharedFolderPath = @"\\Server\SharedFolder"; // Create a WebRequest instance for the shared folder WebRequest sharedFolderRequest = WebRequest.Create(sharedFolderPath); NetworkCredential credentials = new NetworkCredential("username", "password"); sharedFolderRequest.Credentials = credentials; // Get the response from the shared folder request WebResponse sharedFolderResponse = sharedFolderRequest.GetResponse(); // Get the shared folder stream and create a StreamWriter instance Stream sharedFolderStream = sharedFolderResponse.GetResponseStream(); StreamWriter sharedFolderWriter = new StreamWriter(sharedFolderStream); // Get the files and directories in the local folder string[] files = Directory.GetFiles(localFolderPath); string[] directories = Directory.GetDirectories(localFolderPath); // Copy the files to the shared folder foreach (string file in files) { // Get the filename from the file path string filename = Path.GetFileName(file); // Create the shared file path string sharedFilePath = Path.Combine(sharedFolderPath, filename); // Copy the file to the shared folder File.Copy(file, sharedFilePath); } // Copy the directories to the shared folder foreach (string directory in directories) { // Get the directory name from the directory path string directoryName = Path.GetFileName(directory); // Create the shared directory path string sharedDirectoryPath = Path.Combine(sharedFolderPath, directoryName); // Create the shared directory Directory.CreateDirectory(sharedDirectoryPath); // Recursively copy the files and directories in the local directory to the shared directory CopyFolder(directory, sharedDirectoryPath); } // Close the shared folder stream and response sharedFolderWriter.Close(); sharedFolderResponse.Close(); } private void CopyFolder(string sourceFolderPath, string targetFolderPath) { // Get the files and directories in the source folder string[] files = Directory.GetFiles(sourceFolderPath); string[] directories = Directory.GetDirectories(sourceFolderPath); // Copy the files to the target folder foreach (string file in files) { // Get the filename from the file path string filename = Path.GetFileName(file); // Create the target file path string targetFilePath = Path.Combine(targetFolderPath, filename); // Copy the file to the target folder File.Copy(file, targetFilePath); } // Copy the directories to the target folder foreach (string directory in directories) { // Get the directory name from the directory path string directoryName = Path.GetFileName(directory); // Create the target directory path string targetDirectoryPath = Path.Combine(targetFolderPath, directoryName); // Create the target directory Directory.CreateDirectory(targetDirectoryPath); // Recursively copy the files and directories in the source directory to the target directory CopyFolder(directory, targetDirectoryPath); } } ``` 在上面的代码中,我们首先使用WebRequest和NetworkCredential类设置访问共享文件夹所需的凭据。然后,我们使用Directory.GetFiles和Directory.GetDirectories方法获取本地文件夹中的文件和子文件夹,并使用File.Copy方法将文件从本地文件夹复制到共享文件夹。接下来,我们使用Directory.CreateDirectory方法在共享文件夹中创建子文件夹,并递归调用自己,将子文件夹中的文件和文件夹复制到共享文件夹中。最后,我们关闭共享文件夹流和响应。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值