在C#中,如何对一个文件进行共享实现,用代码设置本地文件夹为共享文件夹? 代码如下: 1.引入命名空间: using System.Diagnostics; 2.代码实现: Process p = new Process(); //创建进程对象 string shareName = txtShareName.Text; //共享名txtShareName 界面的文本框 string sharePath = txtShareDisk.Text; //共享路径 txtShareDisk 界面的文本框 p.StartInfo.FileName = "cmd"; //启动进程名称 //执行的命令 p.StartInfo.Arguments =string.Format(" /c net share {0}={1}",shareName,sharePath); //窗口状态为隐藏 p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //启动进程不创建窗口 p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; //从可执行文件创建进程 p.StartInfo.RedirectStandardOutput = true; //将输出写入流中 p.Start(); //启动进程 p.WaitForExit(); //设置无限期等待关联的进程退出 MessageBox.Show("设置共享成功!");