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

T

TaeHo Yoo

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
 
N

Nick Malik [Microsoft]

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.
 
T

TaeHo Yoo

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
 
W

Willy Denoyette [MVP]

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.
 

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