Groups | Blog | Home
all groups > c# > june 2005 >

c# : How to read a file from a different drive on the same machine C# windows based application


TaeHo Yoo
6/29/2005 11:56:36 PM
The file I would like to access in located in C drive and the
application which reads the file is located in E drive. When it trys to
read the file, it generates an error

Error: Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib,
Version=1.0.5000.0, Cu
lture=neutral, PublicKeyToken=b77a5c561934e089 failed.

How to read the file?

Thanks

Nick Malik [Microsoft]
6/30/2005 12:30:51 AM
this has nothing to do with the drive letter. your "read" would fail
regardless of the drive. You do not have permission to read.

Is this, perhaps, an ASP.Net application? If so, your app is probably
running using Network Service permissions, which gives you no access to the
file system. You'll need to either impersonate the user accessing your
site, or impersonate a "service account" (which is an account that you set
up just for your app to use). Check out the impersonate tag in the
web.config file.

--
--- 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.
--
[quoted text, click to view]

TaeHo Yoo
6/30/2005 12:39:39 AM
Thanks Nick,

But this is a windows based application and when I put the application
in C drive where the file ,which this application reads, resides then it
works find but when I move it to other drives other than C then I get
the error.

Thanks



Willy Denoyette [MVP]
6/30/2005 9:41:07 AM
Your E drive is a mapped network share, right? You have to run caspol.exe to
change the CAS policy to fully trust the share.
Check MSDN for details on "Code Access Security" and "caspol".

Willy.


[quoted text, click to view]

AddThis Social Bookmark Button