Solved

File.Exists always returns false

Posted on 2004-04-05
16
895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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
 

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 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