473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

any ideas why this does not work?

Hi for some reason in the code below even when the file exits the
code below never executes int a = 1;
does the path have to contain the entire physical path including the drive?

string validpath = "~/Files/newfile.doc"
if (File.Exists(validpath))
{
int a = 1;
}
Thanks Paul.
--
Paul G
Software engineer.
Nov 19 '08 #1
8 1307
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
Hi for some reason in the code below even when the file exits the
code below never executes int a = 1;
Yep, that would be correct.
Does the path have to contain the entire physical path including the
drive?
The problem is that there is no file actually called "~/Files/newfile.doc" -
think about it...

string validpath = Server.MapPath("~/Files/newfile.doc");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #2
thanks for the response, yep no file as you stated. Do you know if there is
a way in the code to check if a path is just a path or if it is a file with
out causing a runtime error? I have code that only needs to delete a file if
the string is a file and if it is just a path skip any deletion.
Paul.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
Hi for some reason in the code below even when the file exits the
code below never executes int a = 1;

Yep, that would be correct.
Does the path have to contain the entire physical path including the
drive?

The problem is that there is no file actually called "~/Files/newfile.doc" -
think about it...

string validpath = Server.MapPath("~/Files/newfile.doc");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #3
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
>The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...

Do you know if there is a way in the code to check if a path is just a
path
or if it is a file with out causing a runtime error?
if (File.Exists(Server.MapPath(".........")))
{
File.Delete(Server.MapPath("............."));
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #4
You could use Directory.Exists first ?

--
Patrice

"Paul" <Pa**@discussions.microsoft.coma écrit dans le message de groupe de
discussion : CE**********************************@microsoft.com...
thanks for the response, yep no file as you stated. Do you know if there
is
a way in the code to check if a path is just a path or if it is a file
with
out causing a runtime error? I have code that only needs to delete a file
if
the string is a file and if it is just a path skip any deletion.
Paul.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
>"Paul" <Pa**@discussions.microsoft.comwrote in message
news:0A**********************************@microso ft.com...
Hi for some reason in the code below even when the file exits the
code below never executes int a = 1;

Yep, that would be correct.
Does the path have to contain the entire physical path including the
drive?

The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...

string validpath = Server.MapPath("~/Files/newfile.doc");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #5
Thanks for the additional information. I tried
If (File.Exists(Server.MapPath("~/Files/testfile.doc")))
where Files is a folder in my project and this works fine for what is above.

When I try it with a path that does exist to a folder on a different
machine, note without a file like
If (File.Exists(Server.MapPath("\\\\ExternalMachineNa me\\Folder1\\Folder2")))
I get the run time error
Failed to map the path "ExternalMachineName/Folder1/Folder2"

Any ideas, thanks ?
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...
Do you know if there is a way in the code to check if a path is just a
path
or if it is a file with out causing a runtime error?

if (File.Exists(Server.MapPath(".........")))
{
File.Delete(Server.MapPath("............."));
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #6
Seems to work if I remove the Server.MapPath, since a path on an external
machine does not depend on the project location.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...
Do you know if there is a way in the code to check if a path is just a
path
or if it is a file with out causing a runtime error?

if (File.Exists(Server.MapPath(".........")))
{
File.Delete(Server.MapPath("............."));
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #7
re:
!I get the run time error
!Failed to map the path "ExternalMachineName/Folder1/Folder2"
!Any ideas, thanks ?

The account ASP.NET is running as,
needs access permissions to any shared folder in a different computer.

If the application resides on a UNC share, ASP.NET always impersonates
the IIS UNC token to access that share unless a configured account is used.

If you provide an explicitly configured account, ASP.NET uses that account in preference to the IIS UNC token.

To access a folder in an external machine,
you'll need to run ASP.NET as a network account with access permissions to that folder and its files.

Do that by configuring ASP.NET's identity in web.config :

<identity impersonate="true"
userName="domain\user"
password="password" />

Of course, you'll need to create a Windows account for "domain\user" on your server, and run:

aspnet_regiis -GA domain\user

....on the web server, so that the domain account has the necessary
permissions to all the directories on the server which ASP.NET needs access to.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Paul" <Pa**@discussions.microsoft.comwrote in message news:90**********************************@microsof t.com...
Thanks for the additional information. I tried
If (File.Exists(Server.MapPath("~/Files/testfile.doc")))
where Files is a folder in my project and this works fine for what is above.

When I try it with a path that does exist to a folder on a different
machine, note without a file like
If (File.Exists(Server.MapPath("\\\\ExternalMachineNa me\\Folder1\\Folder2")))
I get the run time error
Failed to map the path "ExternalMachineName/Folder1/Folder2"

Any ideas, thanks ?
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
>"Paul" <Pa**@discussions.microsoft.comwrote in message
news:CE**********************************@microso ft.com...
>The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...

Do you know if there is a way in the code to check if a path is just a
path
or if it is a file with out causing a runtime error?

if (File.Exists(Server.MapPath(".........")))
{
File.Delete(Server.MapPath("............."));
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net



Nov 19 '08 #8
Hi thanks for the additional information. I think the app is running on a
UNC share so most likely impersonating the IIS UNC token.
--
Paul G
Software engineer.
"Juan T. Llibre" wrote:
re:
!I get the run time error
!Failed to map the path "ExternalMachineName/Folder1/Folder2"
!Any ideas, thanks ?

The account ASP.NET is running as,
needs access permissions to any shared folder in a different computer.

If the application resides on a UNC share, ASP.NET always impersonates
the IIS UNC token to access that share unless a configured account is used.

If you provide an explicitly configured account, ASP.NET uses that account in preference to the IIS UNC token.

To access a folder in an external machine,
you'll need to run ASP.NET as a network account with access permissions to that folder and its files.

Do that by configuring ASP.NET's identity in web.config :

<identity impersonate="true"
userName="domain\user"
password="password" />

Of course, you'll need to create a Windows account for "domain\user" on your server, and run:

aspnet_regiis -GA domain\user

....on the web server, so that the domain account has the necessary
permissions to all the directories on the server which ASP.NET needs access to.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Paul" <Pa**@discussions.microsoft.comwrote in message news:90**********************************@microsof t.com...
Thanks for the additional information. I tried
If (File.Exists(Server.MapPath("~/Files/testfile.doc")))
where Files is a folder in my project and this works fine for what is above.

When I try it with a path that does exist to a folder on a different
machine, note without a file like
If (File.Exists(Server.MapPath("\\\\ExternalMachineNa me\\Folder1\\Folder2")))
I get the run time error
Failed to map the path "ExternalMachineName/Folder1/Folder2"

Any ideas, thanks ?
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...

The problem is that there is no file actually called
"~/Files/newfile.doc" -
think about it...

Do you know if there is a way in the code to check if a path is just a
path
or if it is a file with out causing a runtime error?

if (File.Exists(Server.MapPath(".........")))
{
File.Delete(Server.MapPath("............."));
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Nov 19 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the...
14
by: David MacQuigg | last post by:
I am starting a new thread so we can avoid some of the non-productive argument following my earlier post "What is good about Prothon". At Mr. Hahn's request, I will avoid using the name "Prothon"...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
3
by: Dave | last post by:
I have always taken it for granted that once RI is in place, no orphan records can be created, and that RI can't be put in place while orphans exist, but today I came across a situation where that...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
8
by: Jim | last post by:
Need some comments from anyone willing to help, please. See the code included below. This compiles with GCC on FreeBSD 4.7. The only point of it is to accept a socket connection. Nothing else...
6
by: sunnyz | last post by:
hi guys :) ..i wanna setup a software company...i'm looking for ppl who have the same passion so that we cud build up more and more of contacts, get new ideas and start the business right...
11
by: hazz | last post by:
before I start filling up the first page of perhaps many pages of code with if/then or switch:case buckets, I wanted to step back and see if there is a better way... I will have a table with up to...
4
by: Jim | last post by:
Hello, I would like to find every occurrence of the string "://" in the index.dat files which store the ie history. Once a line is identified as containing this string, I would process (i.e....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.