Reputation: 8156
Hello,
Once I got this code to work with out any erros, and it downloaded the file.
Now it gives me a permission error,
I don't get the acesscontrol pop up that window should show.
Anyways,
How can I get this code to download my file?
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(txtFTPuser.Text, txtFTPpassword.Text);
byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com
FileSecurity security = File.GetAccessControl(downloadTo);
FileSystemAccessRule rule = new FileSystemAccessRule(@"BUILTIN\Users",
FileSystemRights.FullControl, AccessControlType.Allow);
File.SetAccessControl(downloadTo, security);
try
{
FileStream f = File.Create(downloadTo/*+@"\"+file*/);
f.Write(fileData, 0, fileData.Length);
f.Close();
MessageBox.Show("Completed!");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
Upvotes: 0
Views: 875
Reputation: 536
What is in the 'downloadTo' variable ? I'm a little confused by your code. Since you can perform a GetAccessControl() I assume it must contain your Folder. If it would be your file, it would fail because it doesn't exist yet.
but then your code continues with
FileStream f = File.Create(downloadTo/*+@"\"+file*/);
since you wrote the /* */ your 'file' variable is commented, which makes me assume downloadTo than must contain the full path including the filename.
can you try and hardcode your destination file ?
(e.g. FileStream f = File.Create(@"c:\\users\\your user\\myfile.bin");
As far as I can interpret your code you're trying to write to Folder as such without specifying a filename.
Upvotes: 1