473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How do you open an external file on a WebBrowser Control

I have a problem where I am using the following code to open an external avi file.

I am outputting the code to external html file for debugging purposes and after I have set my security settings in internet explorer it is working fine.

However, when running through a webBrowser control it does nothing. Is there someway of setting the security settings on my webBrowser control or am I missing something completely.

Code I have is :


Expand|Select|Wrap|Line Numbers
  1.  public Form1()
  2.         {
  3.             InitializeComponent();
  4.             MemoryStream HTMLMemory = new MemoryStream();
  5.             StreamWriter HTMLWriter = new StreamWriter(HTMLMemory);
  6.  
  7.             HTMLWriter.Write("<html><body><input type=button onClick=\" window.location='file:///C:/RDR_Expert_Advisory/Anomaly_ID_surfaces_2010_v.avi'\" value=\"Open File\">");
  8.  
  9.             HTMLWriter.Flush();
  10.             HTMLMemory.Position = 0;
  11.             webBrowser1.DocumentStream = HTMLMemory;
  12.  
  13.             // Print code to a txt file
  14.             StreamWriter sw = new StreamWriter("C:\\RDR_Expert_Advisory\\Test.htm");
  15.             StreamReader sr = new StreamReader(HTMLMemory);
  16.             sw.WriteLine(sr.ReadToEnd());
  17.             sw.Close();
  18.             HTMLMemory.Position = 0;
  19.         }
May 25 '10 #1
3 5306
@Rebeccardr
Anyone know why I get a script error on this code?

"An error has occurred in the script on this page."
Line 1
Char 2
Error: Access is denied
Code 0
URL: about:blank
May 26 '10 #2
nukefusion
221 Expert 100+
Hi Rebeccardr,

Welcome to the forums.

I've only really used the WebBrowser control a couple of times and both times I remember it being quite painful. Trying to get JavaScript to work can be a nightmare.

Try something along these lines:

Expand|Select|Wrap|Line Numbers
  1.         public Form1()
  2.         {
  3.             InitializeComponent();
  4.             MemoryStream HTMLMemory = new MemoryStream();
  5.             StreamWriter HTMLWriter = new StreamWriter(HTMLMemory);
  6.             HTMLWriter.Write("<html><body><input ID=\"myButton\" type=button value=\"Open File\">");
  7.  
  8.             HTMLWriter.Flush();
  9.             HTMLMemory.Position = 0;
  10.             webBrowser1.DocumentStream = HTMLMemory;
  11.             while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
  12.             webBrowser1.Document.GetElementById("myButton").Click += element_Click;
  13.  
  14.             // Print code to a txt file 
  15.             StreamWriter sw = new StreamWriter("C:\\RDR_Expert_Advisory\\Test.htm"); 
  16.             StreamReader sr = new StreamReader(HTMLMemory);
  17.             sw.WriteLine(sr.ReadToEnd());
  18.             sw.Close();
  19.             HTMLMemory.Position = 0;
  20.         }
  21.  
  22.         private void element_Click(object sender, HtmlElementEventArgs e)
  23.         {
  24.             webBrowser1.Url = new Uri("file:///C:/RDR_Expert_Advisory/Anomaly_ID_surfaces_2010_v.avi");
  25.         } 
  26.  
Hope it helps.
May 26 '10 #3
That works! Thank you!!!
May 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Luis Ferrao | last post by:
Hi, My Windows Forms application uses the WebBrowser control to open an Excel file since OLE objects are gone in .Net. The application is actualy a clone of the one found in the MS Knowledge...
5
by: Xero | last post by:
How do you display an external file to the user in vb.net? Thanks. -- Xero http://www.chezjeff.net My personal web portal
9
by: Jason Boardman | last post by:
Can anyone tell me how I can write HTML to a WebBrowser control in Visual Basic 6? I want to display HTML in the browser that is generated from within my VB program (as opposed to loading it from...
2
by: Dean Richardson | last post by:
Hello, I am currently building a windows application in VB.NET. At the moment I have a word document saved locally which I open with the WebBrowser control. I cannot seem to save the changes...
0
by: Dean Richardson | last post by:
Hello, I am currently building a windows application in VB.NET. At the moment I have a word document saved locally which I open with the WebBrowser control. I cannot seem to save the...
0
by: =?Utf-8?B?c25naWxi?= | last post by:
I am having 3 issues with the WebBrowser control which may all be related. The HTML for the page is the standard Weather Magnet from weather.com. The actual HTML is at the bottom of this page. ...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
2
by: Jeroen | last post by:
We are experiencing a tuff-to-debug problem ever since we introduced a WebBrowser control into our failry large application. I'm not sure if the problem description below contains enough details,...
2
by: adaikkan | last post by:
I am trying to access a PDFs file in my C# .NET 2.0 project. I have a URL that points directly to the PDF file. when i say webbrowser.navigate(path). The pdf file opens in Acrobat. I want the pdf...
1
by: Warren Tang | last post by:
Hi Does anyone know an open source file manager control for ASP.NET? Thanks in advance. Regards Warren
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.