当前位置:网站首页>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边栏推荐
- Valentine's Day - make an exclusive digital collection for your lover
- Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
- [free sharing] kotalog diary2022 plan electronic manual ledger
- What is the content of game modeling
- Sentinel source code analysis part II - sentinel dashboard console startup and configuration
- Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
- How to build an efficient information warehouse
- Flume learning notes
- 03 -- QT OpenGL EBO draw triangle
- 2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
猜你喜欢

kubernetes集群搭建efk日志收集平台

5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes

第一章:递归求n的阶乘n!

第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数

Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate

第一章: 舍罕王失算

2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)

第一章: 舍罕王失算

Part 28 supplement (XXVIII) busyindicator (waiting for elements)

Chapter 1: recursively find the factorial n of n!
随机推荐
[wallpaper] (commercially available) 70 wallpaper HD free
Xctf attack and defense world crypto advanced area best_ rsa
Floating source code comment (38) parallel job processor
2022 Xinjiang latest construction eight members (standard members) simulated examination questions and answers
The earliest record
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
The most valuable thing
Win10 share you don't have permission
SQL injection for Web Security (1)
Titles can only be retrieved in PHP via curl - header only retrieval in PHP via curl
04 -- QT OpenGL two sets of shaders draw two triangles
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
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
Chapter 1: recursively find the factorial n of n!
Valentine's Day - make an exclusive digital collection for your lover
Detailed explanation of shuttle unity interworking principle
TFs and SVN [closed] - TFs vs SVN [closed]
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
Using the visualization results, click to appear the corresponding sentence