Download image from "no-hotlink" url - c#

I try to download image on stooorage.com using following code
Webclient wc = new Webclient();
wc.DownloadFile(Link,Filepath);
But this is no-hotlink site ?
Link to test:
http://www.stooorage.com/show/3105/11956084_ngoc_han.jpg
Need a trick :(

Related

Download file with File Address c#

Here I download a file from website which works good. But I wanted to download a Folder with contents.
Before Download Example
MyprojectApp/Test.exe
My Code
WebClient wc = new WebClient();
String Filename = "some.txt";
Uri uri = new Uri("http://127.0.0.1/New/" + Filename);
wc.DownloadFileAsync(uri, "some1.txt");
After Download Example(What I need)
MyprojectApp/Test.exe
MyprojectApp/New/some.txt

Delay before starting download of pdf file using DownloadFile C#

I am attempting to download a large 25 megabyte pdf file using the following code:
string url = "http://aaa.aaa/test.pdf";
string clientfile = HttpContext.Current.Server.MapPath("~/123.pdf");
WebClient wc = new WebClient();
wc.DownloadFile(new Uri(url, UriKind.Absolute), clientfile);
However the file signature is corrupted and does not download correctly. Is there a way to delay the file download before the download actually starts?
I know the file is correct since if I download it from a browser, the file is not corrupted.
Thanks
I found the problem. When downloading a pdf file, it is actually zipped in a format called "GZIP". When using a browser, the file is automatically unzipped for the client. When using the WebClient DownloadFile method in .NET, it must be done manually. First create a class to derive the WebClient class as follows:
public class GzipWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return request;
}
}
Then change your code to use the above class:
string url = "http://aaa.aaa/test.pdf";
string clientfile = HttpContext.Current.Server.MapPath("~/123.pdf");
GzipWebClient wc = new GzipWebClient();
wc.DownloadFile(new Uri(url, UriKind.Absolute), clientfile);
The pdf file will now be correctly downloaded and unzipped automatically.

how to download a file using sync webclient request in c# with out showing popup

I am using "webclient" to download and save a file by url in windows application.
here is my code:
WebClient wc = new WebClient();
wc.Headers.Add(HttpRequestHeader.Cookie, cc);
wc.DownloadFile(new Uri(e.Url.ToString()), targetPath);
this is working fine local system.(downloading the file and saved to target path automatically with out showing any popup).
But when i am trying to execute the .exe in server its showing save/open popup.
Is there any modifications require to download a file in server settings.
Please help me to download the file with out showing popup in server too.
thanks in advance..
Finally i got the solution for this issue..
herw the code:
WebClient wc = new WebClient();
wc.Headers.Add(HttpRequestHeader.Cookie, cc);
using (Stream data = wc.OpenRead(new Uri(e.Url.ToString())))
{
using (Stream targetfile = File.Create(targetPath))
{
data.CopyTo(targetfile);
}
}
here i just replaced the code
wc.DownloadFile(new Uri(e.Url.ToString()), targetPath);
with the blow lines:
using (Stream data = wc.OpenRead(new Uri(e.Url.ToString())))
{
using (Stream targetfile = File.Create(targetPath))
{
data.CopyTo(targetfile);
}
}
Now its working fine..
Thanks all for ur response..

How to save Image Control Image in Folder in Asp.net

I know how to save an image to a folder using the fileupload control with the saveas method. But I to take an image from the image control and save it to a file without using the fileupload control n save it in folder.
string filepath = img1.ImageUrl;
using (WebClient client = new WebClient())
{
client.DownloadFile(filepath,Server.MapPath("~/Image/apple.jpg"));
}
Do you know image path? you can get image path from image control and then download image in code:
Download image from the site in .NET/C#
using(WebClient client = new WebClient())
{
client.DownloadFile("http://www.example.com/image.jpg", localFilename);
}
First Get the Url of Image and then using webclient you can save file in folder
string filepath = img1.ImageUrl;
using (WebClient client = new WebClient())
{
client.DownloadFile(filepath,Server.MapPath("~/Image/apple.jpg"));
}
This will save image in Image Folder with ImageName apple...

How can i get website text wothout using web browser?

I tryed to do a webbrowser that fro, him i get the text.
But insted of getting the text is downloading to my computer the file.
How can i get this text without using it?
Thanks
You can use a WebClient:
string output = string.Empty;
using (WebClient wc = new WebClient())
{
output = wc.DownloadString("http://stackoverflow.com");
}

Categories

Resources