Newbie - ASP.net - check network file exists

L

lh

I have some code working - but only if the files I need are on the c: drive.

Dim fs As New FileStream(sFile, FileMode.Open, FileAccess.Read)



I try to check sFile exists like this.

Dim fso As New Scripting.FileSystemObject
If fso.FileExists(sFile) Then

or

If File.Exists(sFile) Then

FileExists or Exists always returns false. I'm trying values like
"P:\tes\photos\leh.jpg" and "\\servername\webfiles\tes\photos\leh.jpg". I
have permissions etc.



What do I do to make this work? I would prefer a solution that uses drive
letter mappings because configuration is usually done by end users, but I
can live with servernames . thanks.



LH
 
N

Nick Malik [Microsoft]

lh said:
I have some code working - but only if the files I need are on the c:
drive.

Dim fs As New FileStream(sFile, FileMode.Open, FileAccess.Read)



I try to check sFile exists like this.

Dim fso As New Scripting.FileSystemObject
If fso.FileExists(sFile) Then

or

If File.Exists(sFile) Then

FileExists or Exists always returns false. I'm trying values like
"P:\tes\photos\leh.jpg" and "\\servername\webfiles\tes\photos\leh.jpg". I
have permissions etc.



What do I do to make this work? I would prefer a solution that uses drive
letter mappings because configuration is usually done by end users, but I
can live with servernames . thanks.



LH
Hello,

First off, your title line says 'ASP.net' so I'm assuming that this code is
running in an ASP.Net page or code behind, correct? If so, then this code
is running on a web server using the web server login account ASPNET. That
account does not have access to network resources, ever.

If you want to access network files, then you need to configure your web
site to log in to some credential and use the access of that account. You
can do this by setting the web site to require a login, and then setting the
ASP.Net application to impersonate the user who logs in. Then, as long as
the user has an account on the machine or domain, then the user will have
access to files just as if that user had logged directly in to the web
server (well... almost. There are a bunch of permissions that you still
don't get from a web site, but you should be able to find the file).

Note that drive letters apply to the client workstation. You do not have
access to those drive letters from code running on the web server. The user
has to give you the name of the file in a manner that is addressable from
the web server (e.g. UNC names)

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top