C# 創建文件到共享目錄 C# create file to share folder

 try
                {
                    // Map a drive
                    System.Diagnostics.Process.Start(@"C:\WINDOWS\system32\net.exe",
                    $"use J: {_fileUploadConst.UploadPath} {_fileUploadConst.Password} /user:{_fileUploadConst.UserName}");

                    // Delay to allow the changs to take effect
                    Thread.Sleep(2000);
            

            // or use File.Save() etc. using var stream = new FileStream(fullFilePath, FileMode.CreateNew); await fileInput.CopyToAsync(stream); stream.Flush(); } catch (Exception ex2) { throw new Exception(ex2.Message); } finally { // Delete the mapped drive System.Diagnostics.Process.Start(@"C:\WINDOWS\system32\net.exe", "use J: /delete"); }

  

映射驅動即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章