Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File.Exists always returns false

Posted on 2004-04-05
16
Medium Priority
?
903 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

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 2000 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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

618 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