1. 程式人生 > 其它 >C# 建立檔案到共享目錄 C# create file to share folder

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"); }

  

對映驅動即可。