473,395 Members | 2,446 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,395 software developers and data experts.

system.IO.File.Exists doesn't working for file that is outside my virtual directory

Max
hi

i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no

if system.IO.File.Exist(file path) then
....
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.

so how to select file from any folder on my PC and chech that it exist
or not

Aug 10 '06 #1
5 4913
It all depends on what the value of "file path" is. Perhaps you could give
us an example of a "file path" that is not found?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Accept the Unexpected.

"Max" <ma***********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
hi

i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no

if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.

so how to select file from any folder on my PC and chech that it exist
or not

Aug 10 '06 #2
Sounds like you would need to use Server.MapPath - are you using it?

http://support.microsoft.com/default...b;en-us;323245

Aug 11 '06 #3
Max
followin is on of the file that gives error

Server Error in '/' Application.
--------------------------------------------------------------------------------

Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg"
is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292

Aug 11 '06 #4
Max

Reg Edit wrote:
Sounds like you would need to use Server.MapPath - are you using it?

http://support.microsoft.com/default...b;en-us;323245

i have used server.mappath following is my code

If file.Exists(Server.MapPath("imagefiles/") & Session("uploadimg"))
Then
img = file.OpenRead(Server.MapPath("imagefiles/") &
Session("uploadimg"))
ReDim byteArr(img.Length)
img.Read(byteArr, 0,
System.Convert.ToInt32(img.Length))
img.Close()
end if

Aug 11 '06 #5
That's caused by the security settings that prevent subscribers of one web
from poking around in the code of another web. Is it an ISP's server?

"Max" <ma***********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
followin is on of the file that gives error

Server Error in '/' Application.
--------------------------------------------------------------------------------

Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg"
is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagef iles\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292

Aug 13 '06 #6

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

Similar topics

2
by: Zeno Lee | last post by:
I'm using File.Exists to test a file on my C: drive. My program was strongly named and had caspol -af run on it to allow it to run from the network. There are 3 ways I am doing this: 1) Run...
9
by: TPS | last post by:
I have a virtual directory where all posted files are stored. The ASP app does not have rights to the share on the other server where the vir dir resides. What is the best way to give the asp...
0
by: Dwaine | last post by:
I got stumpped on this a while back and used a workaround that involved the "same local username/pwd on both servers" method. Now I'd like to find a cleaner method.... The setup: A webApp...
2
by: Danny Miller | last post by:
Hi there, I'm facing a problem that is driving me nuts. The scenario is as follows: 1) Create an empty directory structure e.g. C:\Dev1\TestWebApp 2) Map a virtual directory e.g. TestWebApp...
2
by: BLetts | last post by:
I have an ASP.NET app that must allow users to upload files. The files are stored in a virtual directory. I use Server.MapPath to map from the virtual directory name to a physical path, then the...
4
by: Max | last post by:
hi i have file browser control to select any file and a button to upload file on my web page now when i select any file. now on click of upload button i have check that file exist or no if...
2
by: tshad | last post by:
I am trying to use my IIS web server on my local machine for testing my web site. The problem is that periodically it will not use the virtual directory for the root. This happens for my...
9
by: antonyliu2002 | last post by:
I have a C# class GeneralUtilities.cs , which many of my aspx.cs files will refer to. So, I've put it under the App_Code folder and compiled it to library using csc /target: library from the DOS...
3
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am getting the following error :- 1>------ Build started: Project: Polygon Drawer, Configuration: Debug Win32 ------ 1>Compiling... 1>Dialog.cpp 1>g:\my subjects\3rd semester\project...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.