web browser control in winform with google chrome c# - c#

hello all i am creating a winform app in which i am showing a map to all the user but the problem is web browser control is taking ie7 as a default browser and map is not supporting in that particular browser,
error:
You are using a browser that is not supported by the Google Maps
JavaScript API. Consider changing your browser.Learn moreDismiss
i want to open the map from web browser control but not with ie, i want to show with google chrome to get rid of that error,
and i have many administrative rights in my system i can't use registry
is there any ways to do that?

VS default browser control use IE. You should use cefsharp for chrome browser.
First include the library and initialize like this...
public ChromiumWebBrowser browser;
private void InitBrowser()
{
try
{
if (!Cef.IsInitialized)
{
CefSettings settings = new CefSettings();
settings.BrowserSubprocessPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "CefSharp.BrowserSubprocess.exe");
Cef.Initialize(settings);
}
string url = "www.google.com";
browser = new ChromiumWebBrowser(url);
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
browser.IsBrowserInitializedChanged += browser_IsBrowserInitializedChanged;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void browser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (((ChromiumWebBrowser)sender).IsBrowserInitialized)
{
//if needed then use dev tool
browser.ShowDevTools();
}
}
For more info please see below link...
https://github.com/cefsharp/CefSharp
https://github.com/cefsharp/CefSharp/wiki/Quick-Start

The Browser component uses the Internet Explorer as engine, so if you want another browser you have to find a component for that.
CefSharp uses chromium as engine.

Related

Post using default browser in wpf

I have an application that simulates a post to a web page with post data using the WebBrowser class in a wpf application.
private void openBrowser(CreateDdiRequest postData)
{
string serialisedObject = serializeValues(postData);
string postHeaders = "Content-Type: application/x-www-form-urlencoded";
_browser.Navigate(new Uri(_url), "_blank", Encoding.UTF8.GetBytes(serialisedObject), postHeaders);
}
This opens up the IE web browser and pushes the post data to the site.
Problem I have now is that I want it to open the default browser not IE.
Is there anyway to achieve this?
As far as I know, the browser that will be launched is not always the default one.
Follow these steps :
1° Despending of your Windows version, you should search "Default Programs" on the start menu, or in the settings for Windows 8. Well, Search for the "Default Programs" panel in your computer :)
2° Enter Default programs, and then tap or click Default Programs.
3° Tap or click Set your default programs.
4° Select your browser from the list of programs. As you can (maybe) see, the browser is not default for every possible actions ("The program has 15 out of 20 defaults")
5° Tap or click Set this program as default, and then tap or click OK.
If it's not working, try to launch your browser by its path :
Process.Start(#"%AppData%..\Local\Google\Chrome\Application\chrome.exe",
"http:\www.YourUrl.com");
Of course, it's working for an external URL, maybe not for what you want.
By the way, if you just want to do a POST request, you don't need the webbrowser class.
using (var client = new HttpClient())
{
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();
}
Sources :
HTTP request with post
http://windows.microsoft.com/en-US/internet-explorer/make-ie-default-browser#ie=ie-11
How to launch a Google Chrome Tab with specific URL using C#
To launch the default browser, simply call Process.Start() and pass the form values in the URL.
Process.Start(myUrl)

Spotify authorization code flow (WPF browser control) C#

I'm using Spotify account service (authorization code flow) to get an authorization code by passing in the required parameters (client_id, response_type and redirect_uri. Its a WPF application so i am using the browser control and navigating the user to
https://accounts.spotify.com/authorize/?client_id=myclientId&response_type=code&redirect_uri=someUri
When i copy paste the link in the browser, i see the right stuff i.e page with the Login to Spotify button but when i am navigating through the browser control in my WPF application, it gives me a file download dialog with Authorize.json file to download with Open and Save options, however in some cases it presents the right page to browser code.
Below is my code:
public winOAuthBrowserForm(string navigateTo)
{
InitializeComponent();
webBrowser.Navigated += webBrowser_Navigated;
webBrowser.Navigate(navigateTo);
}
private void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
if(!String.IsNullOrEmpty(e.Uri.Query))
{
//since we are looking for code for authorization that will be exchanged for request token from the server
if (e.Uri.Query.StartsWith("?code=") || e.Uri.Query.Contains("code="))
{
code = HttpUtility.ParseQueryString(e.Uri.Query).Get("code");
this.Close();
}
if (e.Uri.Query.StartsWith("?error=") || e.Uri.Query.Contains("error="))
{
error = HttpUtility.ParseQueryString(e.Uri.Query).Get("error");
this.Close();
}
}
}
And i am calling this control like:
var uri = string.Format(SpotifyAuthUriFormatter, RequestAuthBaseUrl, clientId);
winOAuthBrowserForm form = new winOAuthBrowserForm(uri);
form.ShowDialog();
This is what i see:
UPDATE: When i right click on document and see the properties, i see it changes the URL to something like res://ieframe.dll/navcancl.htm#... I've searched it and found some solutions related to I.E (I'm using latest but you can't be sure that it'll be latest on client machines), some say that its firewall setting. The thing is, it appears sometimes only.
Any ideas? Thanks

Facebook post on own steam not showing

So I'm having trouble with updating the facebook status.
Using the following code:
private const string FacebookPermissions = "user_about_me,publish_stream,read_stream";
try
{
dynamic fbPostTaskResult = await fbclient.PostTaskAsync("/me/feed", new { message = "" + text });
var responseresult = (IDictionary<string, object>)fbPostTaskResult;
fbclient.PostCompleted += fbclient_PostCompleted;
failed = true;
}
catch (Exception e)
{
ObjFBHelper.LoginAndContinue();
}
The problem is that it's shared at all. Can only be viewed by me.
Have checked the facebook settings and it's set to friends.
Have anyone seen this before? Havent got any hits on google.
You need to flick the switch next to “Do you want to make this app and all its live features available to the general public?” on the Status&Review tab in your app dashboard to “Yes” …
Anything posted via an app will only be visible to the general public, if that is set. Otherwise only people with a role in the app (admin/developer/tester) will be able to see the created content.
You need to allow in settings to make it visible for other users.

How can I get the HTML5 GeoLocation feature to work on GeckoFX v22 web browser control for WinForms using C#?

I wanted to implement a web browser control to Geo-location enable my WinForm desktop application.
I have successfully implemented the GeckoFX web browser in my WinForm project. The problem is when visiting a HTML5 Gelocation enabled website/address the "Allow/Deny access" popup does not appear.
As a result the Geo-location does not work. I have confirmed that Geo-location is enabled in preferences and have tested my WinForm using http://html5test.com and the control is listed as supporting Geo-location.
I have already tried to set permissions via the XPCom API for a specific domain so that the pop-up asking for permission would not be needed:
//CREATE nsSTRING
nsAUTF8String i = new nsAUTF8String("http://html5demos.com");
//CREATE NEW URI
var nsII = Xpcom.CreateInstance<nsIIOService>("#mozilla.org/network/io-service;1");
nsIURI uri = nsII.NewURI(i, "Unicode", null);
//CREATE PERMISSION MANAGER
var instancePM = Xpcom.CreateInstance<nsIPermissionManager>("#mozilla.org/permissionmanager;1");
//GEO PERMISSION SETTINGS
uint permission = Convert.ToUInt32(1);
uint expiretype = Convert.ToUInt32(0);
long expireTime = (long)0;
//ADD GEO PERMISSION SETTINGS (THIS SHOULD ALLOW GEO LOCATION TO JUST RUN WITH NO PROMPT)
instancePM.Add(uri, "geo", permission, expiretype, expireTime);
//TEST PERMISSIONS http://html5demos.com
uint testResult = instancePM.TestExactPermission(uri, "geo"); //RETURN SCORRECT SETTING OF 1 = OK
This did return a tested value of 1 but still the Geo-location does not work.
I have already seen this stackoverflow question:
Gecko for windows forms and geolocation. How to accept request for share my location?, but not really sure where to go from there.
I am sure I need to implement the call myself as the control is just the browser window and not all the other bits n bobs that make up a browser application. Does anyone have any suggestions or perhaps have already implemented Geo-location in GeckoFX using WinForms and C#?
Thanks
Andre

Create new instance of a page and obtain URL

i'm a beginner web programmer. I've been coding desktop applications primarily.
Right now, i have created this web app, in Silverlight, that uses a web service of my own for querying the database. The thing is, one of the app functionalities is the ability to open PDF files. I know that silverlight won't let you do this, but using an IFrame on top of the silverlight application you are able to display a page with de pdf file (using acrobat plug in).
So here's the problem, my silverlight app passes the pdf path to the web service and, in return, the web service would create a new Page and pass the new page URI back so that it can be displayed on the IFrame:
Page Code Behing:
public partial class PDFViewer : System.Web.UI.Page
{
string Filename = string.Empty;
public Uri Uri
{
get { return HttpContext.Current.Request.Url; }
}
public PDFViewer(string filename)
{
Filename = filename;
}
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "Application/pdf";
Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.
Response.End();
}
}
WebMethod Code:
[WebMethod]
public string GetReport(string filename)
{
PDFViewer viewer = new PDFViewer(filename);
return viewer.Uri.AbsoluteUri;
}
this only returns the Web service URL.
So the main question is: How to create a page instance and obtain that page URL?
The solution to this might be here:
http://forums.silverlight.net/forums/p/76977/372282.aspx
"In my Silverlight app i open a new web browser by passing in query string my id and the page process it, query the db, retrieve the selected object and renders with the response methods."
I just don't know how to do it.
Any help is greatly appreciated.
Pedro
Maybe this will help.
wherever your silverlight object is embedded put an iframe with id="xContainer"
and from your silverlight code just set its scr to the pdf you're trying to display
HtmlPage.Document.GetElementById("xContainer").SetProperty("src", "http://google.com");

Categories