当前位置:网站首页>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边栏推荐
- TFs and SVN [closed] - TFs vs SVN [closed]
- Chapter 1: King Shehan miscalculated
- BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply
- Foundation of ActiveMQ
- 2022-06-27 网工进阶(十二)IS-IS-开销类型、开销计算、LSP的处理机制、路由撤销、路由渗透
- Pecan — Overview
- Summary of composition materials for 2020 high-frequency examination center of educational resources
- 5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes
- 第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
- Win10 share you don't have permission
猜你喜欢
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
[wallpaper] (commercially available) 70 wallpaper HD free
[leetcode] [SQL] notes
BOC protected tryptophan zinc porphyrin (Zn · TAPP Trp BOC) / copper porphyrin (Cu · TAPP Trp BOC) / cobalt porphyrin (cobalt · TAPP Trp BOC) / iron porphyrin (Fe · TAPP Trp BOC) / Qiyue supply
Day18 - basis of interface testing
BOC protected amino acid porphyrins TAPP ala BOC, TAPP Phe BOC, TAPP Trp BOC, Zn · TAPP ala BOC, Zn · TAPP Phe BOC, Zn · TAPP Trp BOC Qiyue
Basic principle of LSM tree
2022-06-27 网工进阶(十二)IS-IS-开销类型、开销计算、LSP的处理机制、路由撤销、路由渗透
Xctf attack and defense world crypto advanced area best_ rsa
Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
随机推荐
2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)
Valentine's Day - make an exclusive digital collection for your lover
BOC protected phenylalanine zinc porphyrin (Zn · TAPP Phe BOC) / iron porphyrin (Fe · TAPP Phe BOC) / nickel porphyrin (Ni · TAPP Phe BOC) / manganese porphyrin (Mn · TAPP Phe BOC) Qiyue Keke
2022-06-25 advanced network engineering (XI) IS-IS synchronization process of three tables (neighbor table, routing table, link state database table), LSP, cSNP, psnp, LSP
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
[leetcode] [SQL] notes
Chapter 1: find the factorial n of n!
Utilisation de base du cadre unitest
10 smart contract developer tools that miss and lose
Sentinel source code analysis part II - sentinel dashboard console startup and configuration
PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
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
Win10 share you don't have permission
During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
Read the paper glodyne global topology preserving dynamic network embedding
2022-06-30 advanced network engineering (XIV) routing strategy - matching tools [ACL, IP prefix list], policy tools [filter policy]
Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes
第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
Bad mentality leads to different results