diff --git a/WIndows.Forms/Dialogs/NetworkConnectionDialog.cs b/WIndows.Forms/Dialogs/NetworkConnectionDialog.cs
index 5dc587b4..27d91090 100644
--- a/WIndows.Forms/Dialogs/NetworkConnectionDialog.cs
+++ b/WIndows.Forms/Dialogs/NetworkConnectionDialog.cs
@@ -14,7 +14,6 @@ namespace Vanara.Windows.Forms
///
public class NetworkConnectionDialog : CommonDialog
{
- private SafeCoTaskMemHandle lpnres;
private NETRESOURCE nres = new NETRESOURCE();
private CONNECTDLGSTRUCT opts;
@@ -25,10 +24,10 @@ namespace Vanara.Windows.Forms
nres.dwType = NETRESOURCEType.RESOURCETYPE_DISK;
}
- /// Gets the connected device count. This value is only valid after successfully running the dialog.
- /// The connected device count.
+ /// Gets the connected device number. This value is only valid after successfully running the dialog.
+ /// The connected device number. The value is 1 for A:, 2 for B:, 3 for C:, and so on. If the user made a deviceless connection, the value is –1.
[Browsable(false)]
- public int ConnectedDeviceCount => opts.dwDevNum;
+ public int ConnectedDeviceNumber => opts.dwDevNum;
/// Gets or sets a value indicating whether to hide the check box allowing the user to restore the connection at logon.
/// true if hiding restore connection check box; otherwise, false.
@@ -52,6 +51,14 @@ namespace Vanara.Windows.Forms
}
}
+ ///
+ /// Gets or sets a value indicating whether to display a read-only path instead of allowing the user to type in a path. This is only
+ /// valid if is not .
+ ///
+ /// true to display a read only path; otherwise, false.
+ [DefaultValue(false), Category("Appearance"), Description("Display a read-only path instead of allowing the user to type in a path.")]
+ public bool ReadOnlyPath { get; set; }
+
/// Gets or sets the name of the remote network.
/// The name of the remote network.
[DefaultValue(null), Category("Behavior"), Description("The value displayed in the path field.")]
@@ -78,18 +85,24 @@ namespace Vanara.Windows.Forms
opts.dwDevNum = -1;
opts.dwFlags = 0;
opts.lpConnRes = IntPtr.Zero;
+ ReadOnlyPath = false;
}
///
protected override bool RunDialog(IntPtr hwndOwner)
{
- opts.hwndOwner = hwndOwner;
- lpnres = SafeCoTaskMemHandle.CreateFromStructure(nres);
- opts.lpConnRes = lpnres.DangerousGetHandle();
- var ret = WNetConnectionDialog1(opts);
- if (ret == -1) return false;
- ret.ThrowIfFailed();
- return true;
+ using (var lpnres = SafeCoTaskMemHandle.CreateFromStructure(nres))
+ {
+ opts.hwndOwner = hwndOwner;
+ opts.lpConnRes = lpnres.DangerousGetHandle();
+ if (ReadOnlyPath && !string.IsNullOrEmpty(nres.lpRemoteName))
+ opts.dwFlags |= CONN_DLG.CONNDLG_RO_PATH;
+ var ret = WNetConnectionDialog1(opts);
+ opts.lpConnRes = IntPtr.Zero;
+ if (ret == -1) return false;
+ ret.ThrowIfFailed();
+ return true;
+ }
}
}
}
\ No newline at end of file