How to download documents from the URL.
my client sending some URL which contains some of the documents (documents file will be either zip/image/pdf/word).
Currently i am able to download the file when i click the link, then the pop up will come for open,save,save as,etc format.
But, i want without clicking the link, the document should get download from URL and it stored and placed in the particular folder.
How to download the file from URL..?
below is my sample URL...
http://vininet.vini.intranet/ALW1/servlet/Download?auth=basic&event_name=dd2_view&_docbase=docfile&id=23432424AcMED&Revision=LATEST
Thanks.. i tried below code. but, nothing download.
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance. WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename. myStringWebResource = remoteUri + fileName; Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder. myWebClient.DownloadFile(myStringWebResource,fileName);
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
The above code downloaded as image files. what about other format like zip,pdf,xls or .doc and where to mention.?
Tell rather what happens. Sometimes you have to provide a user agent. I tried the following which seems to work fine:
using (var client = new System.Net.WebClient())
{
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
client.DownloadFile("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png","c:\\temp\\Google.png");
}
Edit: the image is blank if I don''t provide a user agent. It just download what the server returns and doesn't care if this a a zip, docx or whatever. You could use client.ResponseHeaders["content-type"] to see which content-type the server tells you it
is...
Member
209 Points
701 Posts
How to download documents from the URL..?
Feb 07, 2019 04:32 AM|gani7787|LINK
All-Star
48500 Points
18071 Posts
Re: How to download documents from the URL..?
Feb 07, 2019 09:27 AM|PatriceSc|LINK
Hi,
Programmatically you could use https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netframework-4.7.2 to download files. Not sure about the big picture such as from where you get those links. Seems anyway a desktop app rather than a web app.
Member
209 Points
701 Posts
Re: How to download documents from the URL..?
Feb 07, 2019 10:34 AM|gani7787|LINK
Thanks.. i tried below code. but, nothing download.
The above code downloaded as image files. what about other format like zip,pdf,xls or .doc and where to mention.?
All-Star
48500 Points
18071 Posts
Re: How to download documents from the URL..?
Feb 07, 2019 02:19 PM|PatriceSc|LINK
Tell rather what happens. Sometimes you have to provide a user agent. I tried the following which seems to work fine:
Edit: the image is blank if I don''t provide a user agent. It just download what the server returns and doesn't care if this a a zip, docx or whatever. You could use client.ResponseHeaders["content-type"] to see which content-type the server tells you it is...
Member
209 Points
701 Posts
Re: How to download documents from the URL..?
Feb 08, 2019 09:34 AM|gani7787|LINK
Thanks..you rock....