分享
为什么问答平台  ›  专栏  ›  技术社区  ›  WorTex

UnauthorizedAccessException,路径为direcotry - UnauthorizedAccessException, path is direcotry

c#
  •  0
  • WorTex  · 技术社区  · 1 周前

    UnauthorizedAccessException .

    试图用谷歌搜索我的问题,试图解决它,但没有任何效果。

    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Security.Principal;
    
    namespace update
    {
        class Program
        {
    
    
    
            static void Main(string[] args)
            {
    
                // Config
                String pname = "Pain v0.2";
                String dlink = "https://pastebin.com/raw/vC44QriZ";
                string title = @"
     .----------------.  .----------------.  .----------------.  .-----------------. .----------------. 
    | .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
    | |   ______     | || |      __      | || |     _____    | || | ____  _____  | || |              | |
    | |  |_   __ \   | || |     /  \     | || |    |_   _|   | || ||_   \|_   _| | || |              | |
    | |    | |__) |  | || |    / /\ \    | || |      | |     | || |  |   \ | |   | || |              | |
    | |    |  ___/   | || |   / ____ \   | || |      | |     | || |  | |\ \| |   | || |              | |
    | |   _| |_      | || | _/ /    \ \_ | || |     _| |_    | || | _| |_\   |_  | || |              | |
    | |  |_____|     | || ||____|  |____|| || |    |_____|   | || ||_____|\____| | || |   _______    | |
    | |              | || |              | || |              | || |              | || |  |_______|   | |
    | '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
     '----------------'  '----------------'  '----------------'  '----------------'  '----------------' ";
                // ---------- Do not touch here if you do not know ----------
                Console.Title ="Pain";
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(title);
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Press ENTER to start downloading files.");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.ReadKey();
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Downloading new Files...");
                WebClient wc = new WebClient();
                String key = wc.DownloadString(dlink);
                String path = Directory.GetCurrentDirectory();
                System.Net.WebClient Dow = new WebClient();
                String patch = (path);
                Directory.CreateDirectory(patch);
                Dow.DownloadFile(key, path);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(pname + " Succesfully downloaded / updated!");
                Console.WriteLine("Press ENTER to close this window.");
                Console.ReadKey();
    
    
            }
    
            }
        }
    
    

    未授权访问异常

    2 回复  |  直到 1 周前
        1
  •  0
  •   dotnetstep    1 周前

     String key = wc.DownloadString(dlink);
                String path = Directory.GetCurrentDirectory();
                System.Net.WebClient Dow = new WebClient();
                String patch = path;
                Directory.CreateDirectory(patch); // Create Directory
                Dow.DownloadFile(key, System.IO.Path.Combine(path,"pain.zip"));
    
        2
  •  0
  •   Amrendra    1 周前

    通过看你的问题,我觉得你可能需要先打开目录。 我想目录应该有一个密码。