I am looking for a method for obtaining the 'real' UNC path from a mapped network drive - a mon question here but not using the language or method that I desire.
I would like users to be able to select a file using an HTML form but not upload it (the files are enormous). All I want to obtain is the full UNC path to the file. The trouble is that users will typically select files out of their mapped network drive (e.g. g:\file.txt) which is of no use to me - I must have the full \\server\user\file.txt
path.
I know that in Windows you can use net use
at the mand line for information about mapped drives, and you can also obtain the information from the HKEY_CURRENT_USER\Network\driveletter
, but I need a method to obtain this from an HTML form.
My initial thought was some form of Javascript, but I doubt the registry key will be accessible in this way.
I am looking for a method for obtaining the 'real' UNC path from a mapped network drive - a mon question here but not using the language or method that I desire.
I would like users to be able to select a file using an HTML form but not upload it (the files are enormous). All I want to obtain is the full UNC path to the file. The trouble is that users will typically select files out of their mapped network drive (e.g. g:\file.txt) which is of no use to me - I must have the full \\server\user\file.txt
path.
I know that in Windows you can use net use
at the mand line for information about mapped drives, and you can also obtain the information from the HKEY_CURRENT_USER\Network\driveletter
, but I need a method to obtain this from an HTML form.
My initial thought was some form of Javascript, but I doubt the registry key will be accessible in this way.
Share Improve this question asked Feb 12, 2013 at 17:24 user1832464user1832464 4- I doubt that this is possible without the use of a local installed ponent. Would it be thinkable of having users install something first? – rene Commented Feb 23, 2013 at 10:42
- 1 if this is on a corporate network then perhaps you could accept the filename as you get it (G:\file.txt) and then use some server-side code to connect back to the user's pc (you should easily be able to get their IP address) and get the list of network drive mappings to work out where the drive letter is assigned to? – paulH Commented Feb 25, 2013 at 16:00
- @monkeymatrix: are you pletely against a simple ActiveX control? – Mike Perrenoud Commented Feb 27, 2013 at 17:24
- Does this need to be done on the client side? If you are using .Net I believe I have a possible solution. – jason Commented Feb 28, 2013 at 18:29
1 Answer
Reset to default 4You can do this really simply with a very concise piece of JavaScript and an already installed ActiveX control. Below is a plete web page that will allow you to browse for a file and then show you the full UNC path of the selected file in an alert
:
<html>
<head>
<script type="text/javascript" language="JavaScript">
if (typeof String.prototype.startsWith != 'function') {
// see below for better implementation!
String.prototype.startsWith = function (str){
return this.indexOf(str) == 0;
};
}
function getUNCPath() {
var fileName = document.getElementById("uploadedFile").value;
var WshNetwork = new ActiveXObject("WScript.Network");
var Drives = WshNetwork.EnumNetworkDrives();
for (i = 0; i < Drives.length; i += 2) {
if (fileName.startsWith(Drives.Item(i))) {
var fullPath = fileName.replace(Drives.Item(i), Drives.Item(i + 1));
alert(fullPath);
break;
}
}
}
</script>
</head>
<body>
<form onsubmit="getUNCPath()">
<input type="file" id="uploadedFile"/>
<input type="submit" value="Get the UNC Path!" />
</form>
<span id="uncPath"></span>
</body>
</html>