I have a situation with Windows APP. I am developing where DownloadFile throws an “cannot find part of the path” exception.
The method that I use to save the remote zip file to my hard drive is as follows:
private void f_begin_download(string remoteURL) { string directoryName = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); //MessageBox.Show(directoryName); filePath = directoryName + "\\tmp\\"; filePath = f_make_directory(filePath); Uri remoteURI = new Uri(remoteURL); System.Net.WebClient downloader = new System.Net.WebClient(); downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(f_downloader_DownloadFileCompleted); try { downloader.DownloadFile(remoteURI, filePath); } catch (Exception ex) { MessageBox.Show(remoteURI.ToString()); MessageBox.Show(filePath); MessageBox.Show(ex.ToString()); } }
This method actually creates the / tmp / folder in the application directory. It also successfully creates the folder:
public static string f_make_directory(string path) { try { System.IO.DirectoryInfo newFolder = new System.IO.DirectoryInfo(path); if (!newFolder.Exists) { newFolder.Create(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return path; }
But when I start the process, the exception looks like this:
System.Net.WebException: An exception occurred during a WebClient request.
in WindowsFormsApplication1.window_updater.f_begin_download (String remoteURL) in C: \ Users \ Hudson Atwell \ Documents \ Visual Studio \ Projects \ Test Project \ Test Project] Windows \ window_update.cs: line 125
I need the solution to run as an administrator.
Any tips on what I'm doing wrong?
source share