How to automatically accept the "Open/Save Dialog" in a WebBrowser Control? - c#

I am working on a c# Windows utility, which is opening a file using webbrowser control.
webBrowser1.Navigate("URL");
URL is actually an attachment, which is showing as "Open" "Save" dialog
private void WebBrowser1_FileDownload(Object sender, EventArgs e)
{
textbox1.text ="filedownload event fired!!"
}
can I do somthing so that i cancel the file open/save dialog in the background.
As I wanted to automate the process and don't want user to get popped up message.

Related

VSTO C# Clickable Links in Task Pane

I have a custom task pane for my Excel VSTO addin. In this task pane I want to display a clickable link (for example "https://stackoverflow.com") to the user which opens the user's browser and navigates to the site when clicked. When I programmatically put the text into the task pane's RichTextBox the text turns blue as if it is being recognized as a URL, however when the text is clicked on nothing happens. Is there a property I need to set for the RichTextBox to allow the link to be clicked on?
You need to handle the LinkClicked event of the RichTextBox.
richTextBox1.LinkClicked += richtextBox1_LinkClicked;
public void richtextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
// Opens the link in the default browser.
Process.Start(e.LinkText);
}

obtain downloaded file path from WebBrowser component

Using the WebBrowser component in C#, is it possible to obtain the file path of a user downloaded file?
For example, a user is browsing an arbitrary website using the WebBrowser then clicks a link to download, say, a PDF. The default download manager pops-up and prompts the user to save the file and the user can download the file to a location of their choice; but I do not know where they have saved that file.
Is this actually possible using the WebBrowser control?
You can try this:
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
WebClient client = new WebClient();
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
client.DownloadDataAsync(e.Url);
}
void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
string filepath = textBox1.Text;
File.WriteAllBytes(filepath, e.Result);
MessageBox.Show("File downloaded");
}
When you host the web browser component, you can handle all the events. So for example, you can handle the right click, override the menu and show your custom menu.
So When the user clicks on a link or right clicks, you can show your own dialog instead of the system dialog and then you can have the path of the downloaded file from your own dialog.

Window.Print() block other google chrome tabs

I am working on ASPx Web Forms Page and have problem with printing page.
I have button 'Print' which calls event (print method):
private void MenuPrint_ItemClick(object sender, DevExpress.Web.ASPxMenu.MenuItemEventArgs e)
{
Response.RedirectOn("Print.aspx", "_blank", "menubar=0,scrollbars=1,width=780,height=900,top=10");
}
after I press 'Print' button it opens new window 'Print.aspx' and this is which is on this Page:
protected void Page_Init(object sender, EventArgs e)
{
LoadData(); // generate print document
Response.Write("<script language=javascript>window.print();</script>");
}
and now it's the problem:
window.print(); will open google chrome printing menu, which block old window (that window where is 'Print' button.
When I close Print.aspx by clicking [X] List.aspx windows will be still blocked. When I press 'Anuluj' - which means Cancel and then press [X] List.aspx won't be blocked. Eveything will be fine.
I make some research and figure out that there is no more options to print document, also I can't handle 'Cancel printing' button.
Question is how to avoid that block, maybe I should use something other instead RedirectOn?
This seems to be a bug of Chrome 34 - is this the Chrome version you are using?
There is a similar question open here: Javascript window.print() in chrome, closing new window or tab instead of cancelling print leaves javascript blocked in parent window.
No solution so far though.

Open YouTube Embedded Player link in default browser

I'm hosting YouTube Embedded Player in C# WebBrowser control. When I click button "Watch on YouTube" IE opens. Is there any way to open the link in default web browser, for instance, Chrome?
Like this for example:
private void browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
System.Diagnostics.Process.Start(e.Url.ToString());
e.Cancel = true;
}
Explanation: change the navigating handler to process the URL and fire the link in the diagnostics (which will open the URL in the user’s default browser).

click on a link event webbrowser c#?

I want to open a link in IE browser from the web browser control in my winform ... the webbrowser control navigate to a page when the user click on a link it opens in the internet explorer browser.
Basically handle the WebBrowser.Navigating Event, cancel the navigation and open up the url in explorer like this:
private void WebBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
Process.Start("iexplorer.exe", e.Url);
}

Categories