private FileInfo DownloadFile(WebClient client, SharePointDocument document, string directory, string fileName) { LogDebug($"Downloading '{fileName} to {directory}"); string filePath = Path.Combine(directory, fileName); Uri fileUrl = new Uri(SiteUrl, document.RelativeUrl); client.DownloadFile(fileUrl, filePath); return(new FileInfo(filePath)); }
/// <summary> /// Downloads the specified document to the specified directory. /// </summary> /// <param name="document">The <see cref="SharePointDocument" /> to download.</param> /// <param name="directory">The directory to download the file into.</param> /// <returns>A <see cref="FileInfo" /> object representing the downloaded file.</returns> /// <exception cref="ArgumentNullException"><paramref name="document" /> is null.</exception> public FileInfo Download(SharePointDocument document, string directory) { if (document == null) { throw new ArgumentNullException(nameof(document)); } return(Download(document, directory, document.FileName)); }
/// <summary> /// Downloads the specified document to the specified directory. /// </summary> /// <param name="document">The <see cref="SharePointDocument" /> to download.</param> /// <param name="directory">The directory to download the file into.</param> /// <param name="fileName">The file name to give the downloaded file</param> /// <returns>A <see cref="FileInfo" /> object representing the downloaded file.</returns> /// <exception cref="ArgumentNullException"><paramref name="document" /> is null.</exception> public FileInfo Download(SharePointDocument document, string directory, string fileName) { if (document == null) { throw new ArgumentNullException(nameof(document)); } using (WebClient client = new WebClient()) { if (Credential != null) { client.Credentials = Credential; } else { client.UseDefaultCredentials = true; } return(DownloadFile(client, document, directory, fileName)); } }