[C#] Copy File Share Trong Mạng Lan Với Chứng Thực Tài Khoản ...

Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn cách copy file từ share folder từ Server về máy local của mình, có chứng thực username và password C# Winform.

[C#] Copy file share LAN with authenticate

Trong hệ thống mạng nội bộ LAN, mình ví dụ chúng ta có share một thư mục với tên Document.

Và Thư mục này chỉ share cho tài khoản: laptrinhvb - pass: thao123456789  login vào được mới chép.

Khi chúng ta truy cập bình Resource như: \\192.168.0.3\document nó sẽ yêu cầu bạn đăng nhập tài khoản chứng thực của mình trên domain vào.

copy_file_share_network_csharp

Khi các bạn đăng nhập chứng thực để share và có lưu "Remember my credentials" thì nó sẽ được quản lý ở đây.

Nếu các bạn không muốn ghi nhớ nữa thì, các bạn có thể vào đây để xóa.

Từ URI của Window explorer, các bạn paste vào đường dẫn sau:

Control Panel\All Control Panel Items\Credential Manager

credential_manager

Các bạn chọn vào Windows Credentials thì sẽ thấy thông tin chứng thực của chúng ta được lưu trữ ở đây:

xoa_chungthuc_windows

Bây giờ, mình sẽ demo ứng dụng copy Fileshare C#:

Đầu tiên, các bạn cài cho mình thư viện NetworkConnection từ Nuget

PM> Install-Package NetworkConnection -Version 1.0.19

Source code Copy File Share From Lan Network C#:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using NetworkConnection; namespace CopyFileShareNetworkWithAuthenticate { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCopy_Click(object sender, EventArgs e) { string _userName = @"HOABINHCO\nguyenthao"; string _password = "xxxxxx"; string _directoryPath = @"\\192.168.0.3\documents"; string localPath = @"E:\release.rar"; using (new NetworkConnection.NetworkConnection(_directoryPath, new NetworkCredential(_userName, _password))) { File.Copy( _directoryPath + @"\release.rar", localPath); } } } }

Thanks for watching!

DOWNLOAD SOURCE

 

Tags: copy file share c#

THÔNG TIN TÁC GIẢ

Founder Founder 1287 bài viết 17,053,736
NGUYỄN THẢO

Founder at LaptrinhVB.net

★★★★★

♥ Tình yêu thương chẳng hề hư mất bao giờ. (Cr 13,4)

=========================================================================

My skills includes .NET(C#, VB.NET), DevExpress, Java, Android, PHP,

Python, Sqlserver, Mysql, Reactjs, Dart, Flutter, API services and lot more...

Phone/Zalo/Telegram/WhatsApp: ☎️ (+84)933.913122

Zalo: https://zalo.me/0933913122

Email: [email protected]

My Github: https://github.com/nguyenthao1988

Facebook: https://fb.com/Lewandowski28031988

Youtube Channel: https://www.youtube.com/@thaomeotv      

=========================================================================

" Gửi tặng tác giả: Thảo Meo ly cà phê đầy năng lượng và cảm hứng. "

Mời Ad ly cafe

BÀI VIẾT LIÊN QUAN

Từ khóa » Gửi File Qua Mạng Lan C#