Solved

File.Exists always returns false

Posted on 2004-04-05
16
887 Views
Last Modified: 2007-12-19
I have a web app on a server.  I want to get a file from another machine.  I'm trying to do something like...

If file.exists("\\machine2\import\myfile.txt") then
   response.write("yes")
Else
   response.write("no")
End if

It always returns no.  Am I able to do this?

Thanks
0
Comment
Question by:barnetjeb
  • 5
  • 5
  • 2
  • +4
16 Comments
 

Expert Comment

by:nomoreself
ID: 10760178
What language are you trying to write this in?  Javascript?  PHP?  C#?
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10760254
Can you access the file if you use the same string in the explorer
0
 
LVL 3

Expert Comment

by:GoSu
ID: 10760292
It may be a permissions issue, if you are running this from asp make sure the impersonated account has permissions. Most likely it will be the local ASP service account (which can't have permissions to network resources) so you would either have to change the account or use another authentication scheme (good for Intranet apps)
0
 

Expert Comment

by:irish_coffee
ID: 10760341
erm.. try to change the code into these
>>
If file.exists("\\\\machine2\\import\\myfile.txt") then
   response.write("yes")
Else
   response.write("no")
End if

probably the problem is with the backslash in the code.

hope it help

0
 
LVL 3

Expert Comment

by:GoSu
ID: 10760393
That's only for Server Side JScript. The If syntax and improper casing suggests VBScript
0
 
LVL 19

Expert Comment

by:webwoman
ID: 10760827
The file has to be accessible from the WEB SERVER, not your machine. Chances are it's not.

And even then, it's difficult to make a network connection work. The IUSR_machine account rarely has network access.
0
 
LVL 7

Expert Comment

by:TheKenman
ID: 10764085
Hi barnetjeb,

Maybe this will help:

   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FileExists("\\machine2\import\myfile.txt")) then
       response.write("yes")
   Else
       response.write("no")
   End if
   Set fso = Nothing

If that doesn't work, try this:

   Dim fso, theFile
   Set fso = CreateObject("Scripting.FileSystemObject")
   theFile = Server.MapPath("\\machine2\import\myfile.txt")
   If (fso.FileExists(theFile)) then
       response.write("yes")
   Else
       response.write("no")
   End if
   Set fso = Nothing
0
 
LVL 19

Expert Comment

by:webwoman
ID: 10764506
I doubt server.mapPath will work.

It will return something like this....
C:\inetpub\\\machine2\import\myfile.txt

Not a valid path.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:barnetjeb
ID: 10764868
OK here is what I tried...

Server.MapPath only works when you are using a relative path.  You cannot do \\machinename, and you cannot map a drive and do something like g:\.

When I run the application from the computer, it works fine.  ie. If I'm on my development machine and I run it sees the path and returns yes.  If I go to another machine and bring up the application on my machine it doesn't work..it returns no.

I can see the path fine in Windows Explorer.

The directory currently has full network access for everyone.

My web.config file has <identity impersonate="true" />.  Is there somewhere else I need to change?

Here is what I'm wondering.  Is this actually running as a computer user as opposed to a domain user (ie. ASPNET, and since that computer is giving network access to everyone (which I presume means everyone in the domain) it doesn't recognize it?  I'm sure that is what it is, something to do which permissions, but I don't know where or what to change to make this work.

Thanks for all the suggestions.  I look forward to your replies.
0
 

Author Comment

by:barnetjeb
ID: 10765431
I'm Using VB.NET
0
 
LVL 3

Accepted Solution

by:
GoSu earned 500 total points
ID: 10767346
The ASP.NET web.config file doesn't have any effect on an ASP classsic page. Here's what you need to do. Easiest way is to be on the console of the
Web Server.

The exact steps may vary depinding on your IIS Version and specific configuration. I'm asumming IIS5.0 with a default setup.

Open the IIS Admin MMC
Start->Settings->Control Panel->Administrative Toos -> Internet Services Manager

On the left Expand the [Computer Name] Node,  then expand Default Web Site.
Keep expanding the application/virtual directories that lead to the ASP page in question.

Generally these settings are usually set on a containing folder (It's a lot easier to keep track) but if you wish you can set this up ONLY on your special asp page:

Right Click the (file | folder) and select Properties
Select the (Directory | File) Security Tab
Click the Edit Button in the group "Anonymous Access and authentication control"
Ensure "Anonymous Access" is checked
Click the Edit Button next to "Account used fropm anonymouse Access"
In this dialog enter a network username\password that has permissions to this file.
OK, Confirm Password, OK, OK, OK.
0
 
LVL 3

Expert Comment

by:GoSu
ID: 10767380
Also note: the Code you gave us will not compile in VB.NET. You HAVE to be using VBScript in ASP Classic.
0
 

Author Comment

by:barnetjeb
ID: 10768262
No I'm using VB.NET.  What doesn't compile about it.  It compiles fine for me.
0
 

Author Comment

by:barnetjeb
ID: 10768267
I'm not using classic ASP.  Will the solution you posted still work for me?
0
 
LVL 3

Expert Comment

by:GoSu
ID: 10768524
barnetjeb, I aplogize.

I had made an incorrect assuption and then confused TheKenman's post (Which is ASP Classic) with your own.

Yes the steps I gave you will work if you keep your web.config as it is
regarding
<identity impersonate="true" />

0
 

Author Comment

by:barnetjeb
ID: 10768959
Thanks GoSu,
I will give this a try and tell you how I make out within a day or so.  I thought my problem had something to do with that, but I just didn't know where to change these settings.  Thanks again.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Practice CSS floating images 2 33
Cordova Camera plugin fails 2 97
WIX Redirect 1 38
.php tree directory? 5 56
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

896 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

11 Experts available now in Live!

Get 1:1 Help Now