WPF webbrowser opens PDF file in Adobe reader window - wpf

I am creating one 32bit WPF application.It needs to show created PDF in WebBrowser control.
While doing ,
"WebBrowser.Navigate(new Url("D:\\TestPDF\\MyDocument.pdf"))";
it opens PDF file in Adobe reader window.
My Need is PDF should be opened inside WebBrowser not in Adobe reader window.
I have also tried WebBrowser.NavigateToStream and WebBrowser.Source but its not working.
What can be solution for this? I am looking forward for help.

Have you checked, that you have the Adobe reader installed for the Internet Explorer? You should also verify, that your Internet Explorer is allowed to open PDF-Files embedded.
Sometimes it helpes, to use another Internet Explorer Rendering Engine. This can be archived in with the following code (be warned: Administrator rights are needed for that).
private void CheckAndFixWebBrowserRenderingEngine()
{
RegistryKey baseRegistryKey = Registry.LocalMachine;
string renderingEngineSubKeyString = #"SOFTWARE";
// 64bit operationg systems have another registry path
if (Environment.Is64BitOperatingSystem)
{
renderingEngineSubKeyString += #"\Wow6432Node";
}
renderingEngineSubKeyString += #"\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
var assemblyValueKey = Path.GetFileName(App.ResourceAssembly.Location);
var renderingEngingeValue = 9999; // check other values below
try
{
RegistryKey sk1 = baseRegistryKey.CreateSubKey(renderingEngineSubKeyString);
var value = sk1.GetValue(assemblyValueKey);
if (value == null || value.ToString() != renderingEngingeValue.ToString())
{
sk1.SetValue(assemblyValueKey, renderingEngingeValue);
LogHandler.Instance.Add(string.Format("Did update webbrowser rendering engine from {0} to 9000.", value == null ? "[missing]" : value));
}
}
catch (Exception ex)
{
LogHandler.Instance.Add("Could not check webbrowser rendering engine in registry.");
LogHandler.Instance.Add(ex.ToString(), Logging.LoggingPriorities.Exception);
}
/*
9999 (0x270F)
Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328)
Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
8888 (0x22B8)
Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
*/
}

Related

SaveFileDialog in WPF on Windows XP shows empty file list

I'm using a Microsoft.Win32.SaveFileDialog in a WPF application which is fine in Windows 10 but some users are still using Windows XP and initially the dialog shows no files.
Changing the file type to another type updates the list. It appears to only be the initial loading.
I've used System.Windows.Forms.SaveFileDialog, using a "Using", making sure the Dialog has an owner Window and using BeginInvoke on the current dispatcher.
lSaveFileDialog = new Microsoft.Win32.SaveFileDialog();
lSaveFileDialog.Title = "Datei speichern";
lSaveFileDialog.InitialDirectory = pFilenameElements.IFilenameElement_DirectoryInfo.FullName;
lSaveFileDialog.Filter = "Word Dateien (*.doc)|*.doc|Alle Dateien (*.*)|*.*";
lSaveFileDialog.RestoreDirectory = true;
lSaveFileDialog.FileName = pSuggestedFilename;
if (lSaveFileDialog.ShowDialog() == true)
{
return lSaveFileDialog.FileName;
}
I expect the Dialog to open and display other Word files in the current folder but it only does that if I switch the filter to "All" and then I see everything. Switching back to "Word" and I see the Word files.
On Windows 10 there is no problem.

Allow only one Chromium app instance

I have the Chromium source on Windows 7, and launch my custom app with the --app="..url" switch through a .bat file. How can I prevent users from opening more than one instance of my Chromium app? This includes opening the .exe directly, using the .bat file and by selecting "Chromium" from the jump list menu on the task bar.
If the app is launched with the --app="...url" flag, then the following solution will prevent further "instances" of Chrome being opened. I say "instances" because Chrome doesn't actually create new Chrome base processes. Instead, it opens a new window with a process used for rendering that particular window.
So, when the app is in --app mode, all you need to do is prevent new windows from opening. This can be accomplished by modifying the OpenApplicationWindow() method within the Chromium source code Application_launch class: chrome/browser/ui/extensions/application_launch.cc.
...
OpenApplicationWindow(const AppLaunchParams& params) {
browser = chrome::FindBrowserWithProfile(profile, params.desktop_type);
#endif
WebContents* web_contents;
if (!browser) {
browser = new Browser(browser_params);
web_contents = chrome::AddSelectedTabWithURL(
browser, url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
web_contents->GetRenderViewHost()->SyncRendererPrefs();
}
else {
web_contents = browser->tab_strip_model()->GetActiveWebContents();
}
browser->window()->Show();
...
*NOTE: There should be some Windows 8 code in this method already. The idea is to remove the conditions for Windows 8 Metro Mode, so new Windows are always prevented.

WPF webrowser control - flash working only first time

I have a very strange problem on my wpf application.
I use a webbrowser control to display a third-party web page that uses flash to provide some functionality.
On internet explorer 9 and 10 i have a particular behaviour : the first time I open the webbrowser control everything works fine, and the application puts a .SWF file inside my temporary internet files folder. When I close and reopen the webcontrol, the following error arise :
"object does not support property or method 'UpdateTimeLeft'".
If i manually delete the .SWF file inside the temporary folder, close ad reopen the application, everything works fine again.
This is the code that arise the exception :
var swfUrl = "//" + serverName + "/js/tv/FlashTurboLotto3.swf";
var expressSwfUrl = "//" + serverName + "/js/tv/expressInstall.swf";
var flashvars = {};
var params = {wmode:"transparent", allowscriptaccess:"always" };
var attributes = {id:"FlashTurboLotto3", name:"FlashTurboLotto3", align:"top"};
swfobject.embedSWF(
swfUrl,
"flashcontent",
"100%",
"197",
"9.0.0",
expressSwfUrl,
flashvars,
params,
attributes
);
function updateTimeleft(drawID, timeleft)
{
var swf = document.getElementById("FlashTurboLotto3");
swf.updateTimeleft(parseInt(drawID), timeleft);
}
does anyone have an idea of why this appens and how to solve the issue?
Thank in advance.
I found the solution - It is a very particular bug of Flash. Sometimes happens that when the flash application runs in a non-native browser (like, in my case, a webbrowser control in WPF) the javascript fails at retrieving the .swf file from the cache, so the Flash object will not get initialized.
I solved, for now, by forcing to not use the browser cache, simply adding a random value to the .Swf download Url.

Set WPF webbrowser control to use IE10 mode

How can I set the WPF webbrowser controls to render pages in iE10 mode or the higher version installed on a machine?
By default, if I create a .net 4 or .net 4.5 application on any machine of OS > Windows 7, it renders the html pages in IE7 mode only. (Please correct me if I am wrong).
How to enable the application to render the html pages in IE10 mode if IE10 is installed on the target machine?
If you don't want to modify the registry and you control the webpage, you can use the
<meta http-equiv="X-UA-Compatible" content="IE=10">
tag in the document's head. I believe it has to be first or immediately following <title> in order to work.
You can use the registry as described here:
http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
EDIT:
for a better explanation you can read this answer too
Will the IE9 WebBrowser Control Support all of IE9's features, including SVG?
For WPF webbrowser control use IE11 mode need , for example, in the constructor of the main window, add the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if(pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
string myProgramName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var currentValue = registrybrowser.GetValue(myProgramName);
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue(myProgramName, 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
If you want to see WPF webbrowser control use IE11 mode in DEBUG mode when run from visual studio, you need to add in the registry all progmam "*". This can be done with the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if (pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
var currentValue = registrybrowser.GetValue("*");
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue("*", 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
Checked for windows 10 and visual studio 2015.
Remark: codes other versions of internet explorer, see here https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation

Windows Phone 8.1 live tile background task

I have a Windows Phone 8 app that I recently upgraded to 8.1 Silverlight. I'd like to use the new tile templates. Right now I have a ScheduledTaskAgent that uses ShellTile.
In order to use the new live tiles I changed the notification service to WNS in my WMAppManifest.xml. I removed the code to register the old background task and added this code instead:
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "LiveTileBackgroundTask")
{
task.Value.Unregister(true);
}
}
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "LiveTileBackgroundTask";
taskBuilder.TaskEntryPoint = "BackgroundTasks.LiveTileBackgroundTask";
taskBuilder.SetTrigger(new TimeTrigger(15, false));
var registration = taskBuilder.Register();
}
I created a Windows Phone 8.1 Windows Runtime Component called BackgroundTasks that contains a BackgroundTask called LiveTileBackgroundTask:
public sealed class LiveTileBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
const string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideText01'>"
+ "<text id='1'>Text Field 1 (larger text)</text>"
+ "<text id='2'>Text Field 2</text>"
+ "<text id='3'>Text Field 3</text>"
+ "<text id='4'>Text Field 4</text>"
+ "<text id='5'>Text Field 5</text>"
+ "</binding> "
+ "</visual>"
+"</tile>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
TileNotification tileNotification = new TileNotification(doc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
deferral.Complete();
}
}
I added a reference to this assembly in my Windows Phone project.
I also added a Background task declaration in my Package.appxmanifest that has BackgroundTasks.LiveTileBackgroundTask as an Entry point. I selected Timer and System event as supported task types.
When I run the app though, nothing happens. No live tile appears. I ran through the background task and everything goes well without any exceptions.
You say "No live tile appears". The code you've posted does not create a live tile - it just updates one. You have to manually pin it - the primary tile cannot be pinned through code.
If that's not the problem, maybe you're not looking at the wide tile? This template is for a wide tile, so the square tile won't be updated by this. I'd suggest using the NotificationsExtensions library. It was originally for Windows Store apps, but I think it would work for WP as well. (I've used it, but just for a test, not for real, so there may be issues.) It allows you to easily specify the template and params for both wide and square tiles.
And finally, to have a wide tile, you have to manually edit the Package.appxmanifest file. You must add the Wide310x150Logo attribute to the DefaultTile element.
That's all I can think of. Hope it helps.
Continuous background execution is not supported for Silverlight 8.1
apps
Windows Phone 8 apps can continue to run in the background after the
user navigates away from the app under certain conditions. This
feature is not available for Silverlight 8.1 apps. If you need this
feature, you should continue to use a Windows Phone 8 app. For more
information, see Running location-tracking apps in the background for
Windows Phone 8.
Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps
Windows Phone 8.1 Windows Runtime Component can only be used with Windows Phone 8.1 Runtime(Store) app

Resources