Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create windows service which download file from URL and store it into local path.

My code is like...


<pre>
string destPath = Environment.SystemDirectory + @"\oobe\Info\backgrounds\";
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(destPath);
}
Stream str = null;
string _URL = "http://localhost/exercise2/bin-debug/Background/backgroundDefault.jpg";
//Create a web request to the url containing the image
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(_URL);

//gets the response from the web request
HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();

//return the image stream from the URL specified earlier
str = wRes.GetResponseStream();

if (str != null)
{
Image.FromStream(str).Save(destPath + "backgroundDefault.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
str.Flush();
}

</pre>

When service execute that time it gives error like
Error! A generic error occurred in GDI+.
Any Idea about creating windows service for download file in some interval time and store it in local location????

Help me....
Posted

1 solution

Have a look at this thread[^]. If you implement the solution provided, your problem should get solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900