当前位置:网站首页>How to check the permission to write to a directory or file- How do you check for permissions to write to a directory or file?
How to check the permission to write to a directory or file- How do you check for permissions to write to a directory or file?
2022-07-03 19:38:00 【Technology feast】
problem :
I got a program that writes some data to a file using a method like the one below. I have a program , Use the method shown below to write some data to the file .
public void ExportToFile(string filename){ using(FileStream fstream = new FileStream(filename,FileMode.Create)) using (TextWriter writer = new StreamWriter(fstream)) { // try catch block for write permissions writer.WriteLine(text); }}When running the program I get an error: An error occurred while running the program :
Unhandled Exception: System.UnauthorizedAccessException: Access to the path 'mypath' is denied. Unhandled exception :System.UnauthorizedAccessException: Deny access to path 'mypath'.at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolea bFromProxy) stay System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,nt32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions ptions,SECURITY_ATTRIBUTES secAttrs) System.IO.FileStream..ctor Medium String String msgPath,Boolean bFromProxy( String path ,FileMode Pattern ,FileAccess visit FileShare share ,Int32 bufferSize,FileOptions Options , character string msgPath,Boolea bFromProxy)
Question: What code do I need to catch this and how do I grant the access? problem : What code do I need to use to get this information and how to grant access ?
Solution :
Reference resources : https://stackoom.com/en/question/Xyj边栏推荐
- The way to treat feelings
- How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
- This Chinese numpy quick look-up table is too easy!
- 2022-06-27 网工进阶(十二)IS-IS-开销类型、开销计算、LSP的处理机制、路由撤销、路由渗透
- Utilisation de base du cadre unitest
- Octopus online ecological chain tour Atocha protocol received near grant worth $50000
- I didn't cancel
- Chapter 1: simplify the same code decimal sum s (D, n)
- Day11 ---- 我的页面, 用户信息获取修改与频道接口
- 2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)
猜你喜欢

04 -- QT OpenGL two sets of shaders draw two triangles

Chapter 1: find the algebraic sum of odd factors, find the same decimal sum s (D, n), simplify the same code decimal sum s (D, n), expand the same code decimal sum s (D, n)
![Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue](/img/5b/fc776a1982e24b82984d82be6a016f.jpg)
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue

Think of new ways

03 -- QT OpenGL EBO draw triangle

原生表格-滚动-合并功能

Day_ 18 IO stream system

If the warehouse management communication is not in place, what problems will occur?
![Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles](/img/70/6fd00146418e5d481e951d51428990.png)
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles
![2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]](/img/b6/5d6b946d8001e2d73c2cadbdce72fc.png)
2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]
随机推荐
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
Php based campus lost and found platform (automatic matching push)
UE source code analysis: uccharactermovementcomponent - rootmotion
Latex image rotates with title
PR FAQ: how to set PR vertical screen sequence?
Bad mentality leads to different results
I study database at station B (4): DQL
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
math_ Taylor formula
The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
Kubernetes cluster builds efk log collection platform
Chapitre 1: le roi de shehan a mal calculé
BOC protected alanine porphyrin compound TAPP ala BOC BOC BOC protected phenylalanine porphyrin compound TAPP Phe BOC Qi Yue supply
Day10 ---- 强制登录, token刷新与jwt禁用
BUUCTF
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue
Sentinel source code analysis part II - sentinel dashboard console startup and configuration
unittest框架基本使用
第一章:三位阶乘和数,图形点扫描
Detailed explanation of shuttle unity interworking principle