Solved

File.Exists always returns false

Posted on 2004-04-05
16
886 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

708 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

21 Experts available now in Live!

Get 1:1 Help Now