Solved

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

Posted on 2004-04-21
17
1,063 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:ssdanu
  • 6
  • 4
  • 3
  • +2
17 Comments
 
LVL 30

Expert Comment

by:third
ID: 10885999
i don't think there is a way to do that.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 10887188
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 10887195
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
 
LVL 25

Expert Comment

by:devic
ID: 10888847
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 10893013
devic,
How can that answer the question "Determine a universal network path from a drive letter"?
0
 
LVL 25

Expert Comment

by:devic
ID: 10893090
@ 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
 
LVL 49

Expert Comment

by:DanRollins
ID: 10894079
If you already know the mapping, then there would seem to be no need to find it out...
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 25

Expert Comment

by:devic
ID: 10894162
i agree, but as i understood, ssdanu needs it :)
0
 

Author Comment

by:ssdanu
ID: 10896072
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 10897135
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
 
LVL 8

Expert Comment

by:Dranizz
ID: 11206798
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 11207089
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
 
LVL 8

Expert Comment

by:Dranizz
ID: 11208825
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
 
LVL 8

Expert Comment

by:Dranizz
ID: 11211460
Nevermind, does not work, I realised that it was doing the same thing, same error... I bugged here!
0
 
LVL 8

Assisted Solution

by:Dranizz
Dranizz earned 250 total points
ID: 11211741
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now