Determine a universal network path from a drive letter path using input type-file and javascript

HI


I am using <input type=file>  tag to give user the place to browse and select the  link to the file.IO want tio store those liks in the database. But I ant to store actual path names from the  mapped path name user has selected thru browse. What is the way to do that

 e.g user has selected path

I:\Welcome.asp

where I drive is mapped to
\\MM5206\DQ


so the actual path of the file is

\\MM5206\DQ\welcome.asp

I want to store this actual path in the database instead of the path I:\welcome.asp wntered by the user  after he is finished selecting the path.
 PLease help me by telling the way to do it

 It is very urgent!!



 Thanks in advance

Best Regards
ssdanu
ssdanuAsked:
Who is Participating?
 
DanRollinsConnect With a Mentor Commented:
Here, ya go!  All tied up with a bow :o)

<HTML><BODY>
<input type=button value="reload (if you edit the script)"
       onclick= "document.location.reload();" >
<br>
<input id="ctlFile" type=file>
<br>
<input type=button onclick="DoTest();" value="Do Test">
<script>
function DoTest()
{
      var sFile= document.all.ctlFile.value;
      var sDrive= sFile.substr(0,2);  // e.g., "I:"

      var oNet= new ActiveXObject("WScript.Network");
      var oDrives= oNet.EnumNetworkDrives();

      var sUNC="*not found*";

      for (j=0; j<oDrives.count(); j+=2 ) {
            if ( oDrives.Item(j) == sDrive ) {
                  sUNC= oDrives.Item(j+1);
                  break;
            }
      }
      alert( sUNC );  // here it is!
}

</script>
</BODY></HTML>
0
 
thirdCommented:
i don't think there is a way to do that.
0
 
DanRollinsCommented:
BTW: DOn't expect to be able to do this without using an ActiveX object... that would be a security breach, and nobody wants THAT!
-- Dan
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
devicCommented:
maybe this:
=============
<script>
function runit(obj)
{
      obj.form.userpath.value="\\\\MM5206\\DQ\\"+obj.value.replace(/^[a-z\:\\]{3}/i,"")
}
</script>
<form>
      <input type=file name=userfile onchange=runit(this) style=width:700px><br>
      <input type=text name=userpath style=width:700px>
</form>
0
 
DanRollinsCommented:
devic,
How can that answer the question "Determine a universal network path from a drive letter"?
0
 
devicCommented:
@ DanRollins,

i know that:
   I:\ drive is mapped to  \\MM5206\DQ

i know where file is now
    I:\Welcome.asp


examples:
I:\Welcome.asp
     \\MM5206\DQ\ + Welcome.asp =  \\MM5206\DQ\Welcome.asp

I:\AnotherFolder\Welcome.asp
 \\MM5206\DQ\ + AnotherFolder\Welcome.asp =  \\MM5206\DQ\AnotherFolder\Welcome.asp

i think is right, not tested, just an idea.
0
 
DanRollinsCommented:
If you already know the mapping, then there would seem to be no need to find it out...
0
 
devicCommented:
i agree, but as i understood, ssdanu needs it :)
0
 
ssdanuAuthor Commented:
Hi

 I tried the code given by DanRollins
It gave an exception thata Automation server cannot create object
Whata do I need to do in addition to get thata code work.
 What could be the reason for that exception
And one more thing is user may add different mapped paths it is not fixed as user will everytime add (I:\  path).
 Also it is quite possible that different users can have different mapped drive for same network location
and I would not be knowing these mapped drives already.
so it has to be decided at the runtime as to what location the user entered path is mapped to...


So I need some way to dynamically determine the mapped drives actual network location


Thanks and Regards
ssdanu

0
 
DanRollinsCommented:
THat's what I thought... you need to learn the UNC path at runtime.

The "WScript.Network" activeX object is available on a standard install of Win2000.  As it *is* an activeX, there are several things that mught prevent it from running on some (many) computers becasue of security reasons.  

Try putting that code into a file named TEST.HTA and double-click it to run it on your own computer.
0
 
DranizzCommented:
I have exactly the same problem. Dan Rollins' solution is good but the only problem is that it won't create the ActiveX object. Is it a security problem? Cause I have tried it in a .HTA file and it works fine.
0
 
DanRollinsCommented:
There is a security problem when running ActiveX code called from an HTML script -- because HTML scripts need to run in a "sandbox"  That is, the user is specifically protected from running programs that could harm the computer or give away information to anyone who wants it.  HTA files are "local application prograams" which are treated under a different security scenario -- the same as an EXE or BAT file.  It is assumed that the operator explicilty wants to be able to run this program... unlike a click on a web page where the user may or may not want to run the program.
0
 
DranizzCommented:
Maybe I have a solution. I tried using VBScript instead of Javascript, and it worked. For my part I can do this cause i'm using Script in completion of my ASP.NET pages.

Try using :

dim oBj
Set oBj = CreateObject(("WScript.Network")

0
 
DranizzCommented:
Nevermind, does not work, I realised that it was doing the same thing, same error... I bugged here!
0
 
DranizzConnect With a Mentor Commented:
Whoohoo! It's working!

Here's the article that said how to set the security to permit ActiveX object. It was simple but hard to figured it out!

http://support.microsoft.com/default.aspx?kbid=195826
0
All Courses

From novice to tech pro — start learning today.