L'accès au chemin d'accès 'C:\text.txt' refusé
Bonjour,
je suis étudiant en informatique et j'ai un projet à réaliser et je dois faire le projet sous C#. J'ai crée un fichier texte que j'ai mis dans le disque C afin de faire un test sur la possiblité d'écrire sur ce fichier mais il s'avère que l'on me met ceci après avoir déboguer.
L'exception System.UnauthorizedAccessException n'a pas été gérée
HResult=-2147024891
Message=L'accès au chemin d'accès 'C:\test.txt' est refusé.
Source=mscorlib
Voici le code.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.Permissions;
namespace WebSecure
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
System.IO.File.AppendAllText("C:\\test.txt", textBox1.Text+" ");
StreamReader creer = new StreamReader("C:\\test.txt");
creer.ReadLine();
textBox2.Text = File.ReadAllText("C:\\test.txt");
creer.Close();
}
}
} |
Merci d'avoir lu.