简体   繁体   中英

Access Denied Error while creating a file using FileStream in C#

FileStream fs=new FileStream("c:/samplehubdata.xml",
                             FileMode.OpenOrCreate,
                             FileAccess.ReadWrite,
                             FileShare.ReadWrite);

You usually cannot create a file on Windows in C:\\ without admin priviliges.

Try creating it in your user folder instead.

Write this to get admin access to write on C

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

to your app.manifest You can create this file if you are not able to see the app.manifest. If you want to know more about the app.manifest you can look here

//edited because he wanted to know how

  1. Go to your project and click add
  2. Select Visual C# Items
  3. Select "Application Manifest File"
  4. Call this app.manifest (I guess it is by default)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM