.NET 4.x Скрипт для помещения файла - C#
Формулировка задачи:
Есть ли такой скрипт или что нибудь для того чтобы из моей web страницы файл скачивался на пк в определонную папку. Тоист задать путь в какую папку должен скачатся файл?
Решение задачи: «.NET 4.x Скрипт для помещения файла»
textual
Листинг программы
void DownloadToFolder(Uri address, string path)
{
HttpWebRequest httpRequest = WebRequest.CreateHttp(address);
using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
string contentDisposition = httpResponse.Headers["Content-Disposition"];
string filename = contentDisposition != null
? new ContentDisposition(contentDisposition).FileName
: Path.GetFileName(httpResponse.ResponseUri.GetLeftPart(UriPartial.Path));
using (var responseStream = httpResponse.GetResponseStream())
using (var fstream = File.Create(Path.Combine(path, filename)))
{
responseStream.CopyTo(fstream);
}
}
}