1

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..enter image description here

sai v
  • 183
  • 1
  • 13

1 Answers1

1

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..

sai v
  • 183
  • 1
  • 13