简体   繁体   English

创建目录、文本文件并使用 TextBox 写入该文本

[英]Creating Directory, Text file and write in that text with TextBox

I have issue with this code Access denied Code is working even when i check the text file i have text but i have Access denied Error我有此代码的问题 访问被拒绝 代码正在工作,即使我检查文本文件我有文本但我有访问被拒绝错误

I tried to add App Manifest and have administrator rights even i try to set security on C drive for full access for my account我尝试添加应用程序清单并拥有管理员权限,即使我尝试在 C 驱动器上设置安全性以完全访问我的帐户

private void button1_Click(object sender, EventArgs e)
    {
       string dir = @"C:\Knjigovodstvo\Firme\"+textBox1.Text+"";
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }

        File.WriteAllText(Path.Combine(dir, "Podaci.txt"), textBox1.Text);
        StreamWriter sw = new StreamWriter(dir);
       sw.WriteLine("" + textBox1.Text + "");
       sw.Close();
   }

Just trying to not having the error because it is working只是试图没有错误,因为它正在工作

Thank you guys found the solution with @AlessandroD'Andria and @Steve help谢谢你们在@AlessandroD'Andria 和@Steve 的帮助下找到了解决方案

private void button1_Click(object sender, EventArgs e)
    {
       string dir = @"C:\Knjigovodstvo\Firme\"+textBox1.Text+"";
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }

        File.WriteAllText(Path.Combine(dir, "Podaci.txt"), textBox1.Text);
        StreamWriter sw = new StreamWriter("Podaci.txt");
       sw.WriteLine("" + textBox1.Text + "");
       sw.Close();
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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