【问题标题】:Copying text from one file into another results in a path denied exception将文本从一个文件复制到另一个文件会导致路径被拒绝异常
【发布时间】:2021-03-23 16:58:58
【问题描述】:

它说文件的路径被拒绝。 找了一个小时没有真正的答案。 请帮忙。

private void btnSetText_Click(object sender, EventArgs e)
{
    using (OpenFileDialog dlg = new OpenFileDialog())
    {
        dlg.InitialDirectory = Application.StartupPath;
        dlg.Filter = "Text Document(*.txt)|*.txt|All Files(*.*)|*.*"; //https://stackoverflow.com/questions/48151581/system-argumentexception-filter-string-not-valid
        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            txtSetText.Text = dlg.FileName;
        }
    }

    System.IO.File.WriteAllText(txtSetText.Text , text);

一切都很好并且有效,但是就在这条线上:

System.IO.File.WriteAllText(txtSetText.Text , text);

我不断访问路径 xyz 被拒绝。如何使其可访问?

【问题讨论】:

标签: c# exception visual-studio-2019


【解决方案1】:

您需要确保您的目标文件没有被其他程序打开,并且您需要确保您的程序用户有权打开和编辑此文件。

【讨论】:

    猜你喜欢
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2010-12-31
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多