public void CreateFile(string urlPath, string rootUrl) { urlPath = urlPath.Replace("about://", string.Empty); var url = new Url(urlPath); var filePath = PathConverter.ToPhysicalPath(urlPath, rootUrl); if (url.IsRelative) { url = new Url(new Url(rootUrl), urlPath); } if (!filePath.StartsWith(_basePath)) { filePath = $"{_basePath}\\{filePath}"; } using (var client = new WebClient()) { try { if (!Directory.Exists(Path.GetDirectoryName(filePath))) { var dirPath = Path.GetDirectoryName(filePath); if (File.Exists(dirPath)) { dirPath += DateTime.Now.ToFileTime(); } Directory.CreateDirectory(dirPath); } client.DownloadFile(url, filePath); } catch (WebException e) { throw new Exception( $"{DateTime.Now}: Failed to download file from url \"{url}\", to path \"{filePath}\"." + $"{Environment.NewLine}[Error]: {e.Message}"); } catch (PathTooLongException e) { throw new Exception($"{DateTime.Now}: Too long path for windows." + $"{Environment.NewLine}[Error]: {e.Message}"); } } }