469,319 Members | 2,356 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Using File.Exists

I am trying to see if a file exists in a virtual directory, and if so run a
method. I try doing File.Exists and the method runs but the file isn't there.

Is there a web version of File.Exists or some otherway to get this type of
functionality without too much heartache???

Thanks

--
D @ premierdata
Nov 19 '05 #1
4 2136
You should be able to use File.Exists, but you need to pass it a full
physical path (ie,c:\inetpub\wwwroot\mySite\someFile.txt)

I assume your problem is that you don't have this full physical path. An
easy way to do it is pass the relative or absolute path to Server.MapPath

File.Exists(Server.MapPath("~/myTemp/file.txt"))

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DE*********@online.nospam" <de*********@online.nospam> wrote in message
news:F1**********************************@microsof t.com...
I am trying to see if a file exists in a virtual directory, and if so run a
method. I try doing File.Exists and the method runs but the file isn't
there.

Is there a web version of File.Exists or some otherway to get this type of
functionality without too much heartache???

Thanks

--
D @ premierdata

Nov 19 '05 #2
Nahh, found a article that talks about authentication issues when trying to
do File.Exists from the web side.

So I am trying a WebClient.Openread(filepath).CanRead.ToString(),

But if the file isn't there I get a 404 error versus a error I textualize to
validate againsts.

Any thoughts on that one?
--
D @ premierdata
"Karl Seguin" wrote:
You should be able to use File.Exists, but you need to pass it a full
physical path (ie,c:\inetpub\wwwroot\mySite\someFile.txt)

I assume your problem is that you don't have this full physical path. An
easy way to do it is pass the relative or absolute path to Server.MapPath

File.Exists(Server.MapPath("~/myTemp/file.txt"))

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DE*********@online.nospam" <de*********@online.nospam> wrote in message
news:F1**********************************@microsof t.com...
I am trying to see if a file exists in a virtual directory, and if so run a
method. I try doing File.Exists and the method runs but the file isn't
there.

Is there a web version of File.Exists or some otherway to get this type of
functionality without too much heartache???

Thanks

--
D @ premierdata


Nov 19 '05 #3
Humm...no idea.

You might try to turn impersonatation on
(http://www.dotnetspider.com/Technology/KBPages/403.aspx)

just to see if that resolves the authentication issue (will likely cause
other issues, but just to troubleshoot...)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DE*********@online.nospam" <de*********@online.nospam> wrote in message
news:36**********************************@microsof t.com...
Nahh, found a article that talks about authentication issues when trying
to
do File.Exists from the web side.

So I am trying a WebClient.Openread(filepath).CanRead.ToString(),

But if the file isn't there I get a 404 error versus a error I textualize
to
validate againsts.

Any thoughts on that one?
--
D @ premierdata
"Karl Seguin" wrote:
You should be able to use File.Exists, but you need to pass it a full
physical path (ie,c:\inetpub\wwwroot\mySite\someFile.txt)

I assume your problem is that you don't have this full physical path. An
easy way to do it is pass the relative or absolute path to Server.MapPath

File.Exists(Server.MapPath("~/myTemp/file.txt"))

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DE*********@online.nospam" <de*********@online.nospam> wrote in message
news:F1**********************************@microsof t.com...
>I am trying to see if a file exists in a virtual directory, and if so
>run a
> method. I try doing File.Exists and the method runs but the file isn't
> there.
>
> Is there a web version of File.Exists or some otherway to get this type
> of
> functionality without too much heartache???
>
> Thanks
>
> --
> D @ premierdata


Nov 19 '05 #4
Hi Dewright,

As you mentioend that you encounter authenticaiton error and 404 error.
I'm a bit confused that whether you're doing the File.Exists check at
clientside app or server side asp.net web app? 404 error is a general
error when the client side request a server doucment on the server which
dosn't acutally exist. And if you're doing this in serverside (in asp.net
app's code), generally the ASP.NET's default process identity should have
the sufficient permission to perform this action. So would you provide some
fruther description on your scenario ?
Looking forward to your response.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| From: "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net>
| References: <F1**********************************@microsoft.co m>
<uB**************@TK2MSFTNGP14.phx.gbl>
<36**********************************@microsoft.co m>
| Subject: Re: Using File.Exists
| Date: Thu, 7 Jul 2005 17:52:14 -0400
| Lines: 74
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <e9*************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 206-248-156-127.dsl.teksavvy.com 206.248.156.127
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:111018
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Humm...no idea.
|
| You might try to turn impersonatation on
| (http://www.dotnetspider.com/Technology/KBPages/403.aspx)
|
| just to see if that resolves the authentication issue (will likely cause
| other issues, but just to troubleshoot...)
|
| Karl
|
| --
| MY ASP.Net tutorials
| http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
| http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
| come!)
|
|
| "DE*********@online.nospam" <de*********@online.nospam> wrote in message
| news:36**********************************@microsof t.com...
| > Nahh, found a article that talks about authentication issues when
trying
| > to
| > do File.Exists from the web side.
| >
| > So I am trying a WebClient.Openread(filepath).CanRead.ToString(),
| >
| > But if the file isn't there I get a 404 error versus a error I
textualize
| > to
| > validate againsts.
| >
| > Any thoughts on that one?
| > --
| > D @ premierdata
| >
| >
| > "Karl Seguin" wrote:
| >
| >> You should be able to use File.Exists, but you need to pass it a full
| >> physical path (ie,c:\inetpub\wwwroot\mySite\someFile.txt)
| >>
| >> I assume your problem is that you don't have this full physical path.
An
| >> easy way to do it is pass the relative or absolute path to
Server.MapPath
| >>
| >> File.Exists(Server.MapPath("~/myTemp/file.txt"))
| >>
| >> Karl
| >>
| >> --
| >> MY ASP.Net tutorials
| >> http://www.openmymind.net/ - New and Improved (yes, the popup is
| >> annoying)
| >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
| >> come!)
| >>
| >>
| >> "DE*********@online.nospam" <de*********@online.nospam> wrote in
message
| >> news:F1**********************************@microsof t.com...
| >> >I am trying to see if a file exists in a virtual directory, and if so
| >> >run a
| >> > method. I try doing File.Exists and the method runs but the file
isn't
| >> > there.
| >> >
| >> > Is there a web version of File.Exists or some otherway to get this
type
| >> > of
| >> > functionality without too much heartache???
| >> >
| >> > Thanks
| >> >
| >> > --
| >> > D @ premierdata
| >>
| >>
| >>
|
|
|

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gary Harvey | last post: by
1 post views Thread by kyma via .NET 247 | last post: by
7 posts views Thread by andylcx | last post: by
52 posts views Thread by paytam | last post: by
5 posts views Thread by Michael Sperlle | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.