Home > Net >  Webbrowser download function implementation, but don't play any dialog
Webbrowser download function implementation, but don't play any dialog

Time:09-24

I want to download a content from invoice integrated service platform,
Think the webbrowser in c # to achieve
But don't want to the pop-up dialog box, the default save to a location,

CodePudding user response:



Download, as if first request to the server, and then to save, I can't think of display system default download dialog box, and let him save the default to a directory

CodePudding user response:

The up
The download as if is to call a js then to the server address

CodePudding user response:

webrequest

CodePudding user response:

It is not necessary to use webbrowser? Set to download and you said I do, silent download to the specified location, but completely silent seems blocked by some "security software, add a loading, if you look at the use, the code is moved to the CSDN forget what is the great god wrote

 
///& lt; Summary>
///c # and the.net download file
///& lt;/summary>
///& lt; Param name="URL" & gt; Download address & lt;/param>
///
///& lt; Param name="Filename" & gt; After the download store address & lt;/param>
///& lt; Param name="Prog" & gt; Used to display the progress bar & lt;/param>
///
Public void DownloadFile (URL string, the string filename, ProgressBar prog)
{
Float percent=0;
Try
{
HttpWebRequest Myrq=(HttpWebRequest) WebRequest. Create (URL);
HttpWebResponse myrp=(HttpWebResponse) Myrq. The method GetResponse ();
Long totalBytes=myrp. ContentLength;
If (prog!=null)
{
Prog. Maximum=(int) totalBytes;
}
The Stream st=myrp. GetResponseStream ();
The Stream so=new FileStream (filename, FileMode. Create);
Long totalDownloadedByte=0;
Byte [] by=new byte [1024].
Int osize=st. Read (by 0, (int) by. Length);
While (osize & gt; 0)
{
TotalDownloadedByte=osize + totalDownloadedByte;
Application.DoEvents();
So, the Write (by 0, osize);
If (prog!=null)
{
Prog. Value=https://bbs.csdn.net/topics/totalDownloadedByte (int);
}
Osize=st. Read (by 0, (int) by. Length);

Percent=(float) totalDownloadedByte/(float) totalBytes * 100;
Persent. Text="download updates" + percent. The ToString () + "%, please do not shut down the software";
Application.DoEvents();
}
So, Close ();
St. Close ();

Persent. Visible=false;
ProgressBar1. Visible=false;
}
The catch (Exception)
{
Throw;
}
}
  •  Tags:  
  • C #
  • Related