FileStream & Access to path denied
Bonjour,
Je souhaite faire un gestionnaire de téléchargement mais j'ai des problèmes de droits d'écriture sur mon disque...
Google parle d'ajouter les droits à l'utilisateur ASPNET au dossier dans lequel je veux écrire mais mon application est en WPF... Donc je ne devrais pas avoir de problème avec les droits d'écriture étant donné que je l'éxécute à partir de mon disque dur !
Voici un peu de 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
| private void Download()
{
using (WebClient wcDownload = new WebClient())
{
try
{
webRequest = (HttpWebRequest)WebRequest.Create(URLTb.Text); //Create a request to the file we are downloading
webRequest.Credentials = CredentialCache.DefaultCredentials; //Set default authentification for retireving the file
webRequest.UserAgent = "Steven";
webResponse = (HttpWebResponse)webRequest.GetResponse(); //Retrieve the response from the server
Int64 fileSize = Convert.ToInt64(webResponse.ContentLength); //Ask the server for the file size and store it
Debug.WriteLine(fileSize);
strResponse = wcDownload.OpenRead(URLTb.Text); //Open the URL for download
strLocal = new FileStream(LocationTb.Text, FileMode.Create, FileAccess.Write, FileShare.None); //Create a new file stream where we will be saving the data (local drive)
int bytesSize = 0; //It will store the current number of bytes we rettrieved from the server
byte[] downBuffer = new byte[2048]; //A buffer for storing and writting the data retrieved from the server
//Loop through the buffer until the buffer is empty
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
Debug.WriteLine(bytesSize);
strLocal.Write(downBuffer, 0, bytesSize); //Write the data from the buffer to the local hard drive
this.Dispatcher.Invoke(new UpdateProgressCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize }); //Invoke the method that updates the label & progress bas
}
}
finally
{
//strResponse.Close();
//strLocal.Close();
}
}
} |
Le problème ce situe ici :
Code:
strLocal = new FileStream(LocationTb.Text, FileMode.Create, FileAccess.Write, FileShare.None);
Le FileAccess.Write ne lui convient pas ;)
Merci de votre aide et bonne soirée,
Steven