Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

launching of excel file from Webbrowser.Navigate() method is too uncertain

$
0
0
After migration of the my application(WPF Application) from VS2010(Framework 4.0) to VS2013(Framework 4.5), the excel is not getting launch from the application.
 
Have used a Web Browser control to embed the excel in the application.
Code used:
<WebBrowser Height="665" x:Name="webbrowse" LoadCompleted="webbrowse_LoadCompleted" Visibility="Visible" Unloaded="webbrowse_Unloaded"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
 
There is button which launches the application in the control. It creates a temporary excel file for which the default template is copied and then this file is set as readonly.
Webbrowse.Navigate(excel file path) is used to navigate to the above created temporary file.
 
The launch of the excel file is very uncertain. Have tried to close the opened excel file and release the memory and the temporary file created also gets deleted once the destructor is called. Yet sometimes excel is not launching.

The button click event has the following code:
Microsoft.Office.Interop.Excel.Workbook excelWorkbook= null                                
String tmpFile = System.IO.Path.GetTempPath() + "tmpTemplateAbs" + DateTime.Now.Ticks.ToString() + ".xlsx";// creates a .xls file
                System.IO.File.Copy(TemplateExcelFile, tmpFile, true);// copies the default template file to the tmp location
                System.IO.File.SetAttributes(tmpFile, System.IO.FileAttributes.ReadOnly);
 
Then navigates to that excel file:
 
webbrowse.Navigate(tmpFile);
 
After the webbrowser’s load completed event is fired it assigns the content of the Webbrowser.Document to excel object created.
Workbook doc = webbrowse.Document as Workbook;
excelWorkbook = doc;

 
Request your help on the same.

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>