Solved

File.Exists always returns false

Posted on 2004-04-05
16
893 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

730 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