The notorious yet unaswered issue of downloading a file when windows security is required
Not possible, AFAIK.
WebClient
andWebBrowser
use different layers to access web.WebClient
uses WinHTTP,WebBrowser
uses UrlMon. Thus, they would have separate sessions (including the authentication cache).That's possible, just use any of UrlMon APIs to download the file, e.g.
URLDownloadToFile
orURLDownloadToCacheFile
. I've just answered a similar question.
On a side note, you don't have to feed in keystrokes to provide authentication credentials. You can implement IAuthenticateEx on WebBrowser
site object for this. Here is more info.
Downloading a file from the web to be attached to an outlook message sent from client
Using a customized browser, yes. (If your client runs windows and has office installed...)
For example, create a .Net winform-program with a IE-browser-control in it.
Add hook to IE-control to get when user clicks a specific a-link.
Then perform a download of file from winform-program, use office-api/automation/3rdpart-control from winform-program to fire up a new mail and add attachment to the mail.
System.Net.Webclient only download 81.4 MB (85,363,075 bytes)
It was internal network proxy which was for some reason dropping the request after 81.4 MB (85,363,075 bytes) were transfered. But the weird thing is webclient was not throwing any exception and was pretending that download was successful.
Fix is to null the proxy so request is processed without going through proxy.
$client.proxy=$null # get rid of proxy
$client.DownloadFile( $Url, $destination )
WebBrowser Control download file in session
It should be simply a matter of emulating the cookies and headers in the WebBrowser session and re-using them to impersonate the session in WebClient, but it looks like you're already hot on that path.
Here's how I'd proceed.
Get cookies and headers from WebBrowser.
Cookies: You can get the cookies from your WebBrowser session by handling the DocumentCompleted event of the WebBrowser control and parsing the cookie set from DocumentCompleted event.
Headers: Use a proxy like Fiddler [www.fiddler2.com/] to read the headers so you'll know what's required by the server.
Utilize identity collected above for WebClient.
Headers: Iterate through all your collected headers and be sure they are added to the webclient using
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
for exampleCookies: See this post.
Related Topics
Explicit Conversion Operator Error When Converting Generic Lists
When to Use Properties Instead of Functions
Convert Newtonsoft.JSON.Linq.Jarray to a List of Specific Object Type
Getting Current Directory in .Net Web Application
Converting String to Float in C#
How to Test Database-Related Code with Nunit
How to Format Datetime to Web Utc Format
Send JSON via Post in C# and Receive the JSON Returned
How to Hide Wpf Datagrid Columns Depending on a Property
Datetime to String with Time Zone
The Name '...' Does Not Exist in the Current Context
Testinitialize VS Classinitialize
Looking for a Command Line Argument Parser for .Net
How to Generate a Unique Token Which Expires After 24 Hours
How to Store JSON in an Entity Field with Ef Core
Register Background Task in Silverlight 8.1 App