ReportViewer Custom Protocol - wpf

I am using the ReportViewer in my WPF application and I am trying to get a custom protocol to work with the application. So I get the ability to open sub-programs inside my application when a url is clicked inside the ReportViewer.
When I click on the custom-protocol-url (inside the ReportViewer) nothing happens.
When I open the same report via the Web-Browser, my URL works flawlessly.
It seems like the ReportViewer doesn't allow custom protocols? Has anyone experienced that aswell? Is there any documentation on that?
http, https and mailto are working in the ReportViewer.
I am just adding an Action in the Report pointing to my url
customurl://123
Url definition:
[HKEY_CLASSES_ROOT\customurl]
#="URL: customurl Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\customurl\shell]
[HKEY_CLASSES_ROOT\customurl\shell\open]
[HKEY_CLASSES_ROOT\customurl\shell\open\command]
#="\"C:\\Extra Programme\\TestAlert.exe\" \"%1\""
Testalert (just the test-program by microsoft):
static string ProcessInput(string s)
{
// TODO Verify and validate the input
// string as appropriate for your application.
return s;
}
static void Main(string[] args)
{
Console.WriteLine("Alert.exe invoked with the following parameters.\r\n");
Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);
Console.WriteLine("\n\nArguments:\n");
foreach (string s in args)
{
Console.WriteLine("\t" + ProcessInput(s));
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}

I have looked into the code of ReportViewer and found an if statement, that checks if the url starts with either http:// or https:// or mailto:.
It gets this information with Uri.UriSchemeHttp, Uri.UriSchemeHttps and Uri.UriSchemeMailto
So you could overwrite eg. Uri.UriSchemeHttp with "customurl" (if your url is customurl://123) before rendering the report.
var field = typeof(Uri).GetField("UriSchemeHttp");
field.SetValue(null, "customurl");
The more elegant solution would be, to use a webbrowser control and just show the SSRS Web-Page

Related

CefSharp load a page with browser login

I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.
public MainWindow()
{
InitializeComponent();
BrowserSettings settings = new BrowserSettings();
Cef.Initialize(new CefSettings());
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
licence_grid.Children.Add(webBrowser);
webBrowser.Address = "http://myurlToLoad the page";
}
The problem is when I used a normal url the page load.
But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else.
Can someone give me some tracks to follow...
Thanks
It sounds like the popup you are referring to is in fact the site prompting for basic authentication.
In that case you need to provide an IRequestHandler.GetAuthCredentials handler.
As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.
anybody consuming cefsharp need to implement the authentication dialog. and changes in method is
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
string host, int port, string realm, string scheme, IAuthCallback callback)
{
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
// shyam - original implemenation.
//callback.Dispose();
//return false;
bool handled = false;
// Instantiate the dialog box
AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.
// Open the dialog box modally
dlg.ShowDialog();
if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
{
// The user did not cancel out of the dialog. Retrieve the username and password.
callback.Continue(dlg.UserName,dlg.Password);
handled = true;
}
return handled;
}

Facebook UserName WPF

Its very simple question, I'm new to this and I can't understand the problem , I am trying to get the user name and display it in a label , when i try this code to get the access token it doesn't enter the condition :
it enters the event of (browser_navigated) but not the Conditions in , anyone knows whats the problem ?
private void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult result;
if (FacebookOAuthResult.TryParse(e.Uri, out result))
{
if (result.IsSuccess)
{
var accesstoken = result.AccessToken;
}
else
{
var errorDescription = result.ErrorDescription;
var errorReason = result.ErrorReason;
}
}
There is an annoying bug in wpf browser control which ignores everything after #. (This is only for web browser controls based on wpf so it is present in silverlight and wp7 web browser controls as well.)
Facebook returns access token as part of url fragment.
https://url.com#access_token=....
Due to the bug, when you pass e.Uri as a parameter it doesn't part #access_token=.. thus fb c# sdk thinks it is not a valid oauth callback url and thus TryParse always returns false.
Solution:
Either use the winforms browser control for login or set response_type as code token and then exchange code for access token.

How to pass a search term to Bing from silverlight or google

Has anyone had any luck passing from Silverlight to Bing or Google a url parameter based string that will open search results in a browser. I have been using the Bing API and been able to search and return results within the client and I have also done this using JSON and passing values to the Google API. However if you want to just send a query string to either service and have the results returned via a browser result list I have not found this to be possible. What I am trying to see if it is possible to pass a term "gocart" to Google or Bing as a url (http:www.bing.com/query?gocart) and it return in a new browser window results of the search term. From my initial research both search engines appear to prevent unauthorized queries via URL, I was curious if anyone found it different.
thanks
I have made a hyperlink class:
private class HyperlinkButtonWrapper : HyperlinkButton
{
public void OpenURL(string navigateUri)
{
OpenURL(new Uri(navigateUri, UriKind.Absolute));
}
public void OpenURL(Uri navigateUri)
{
base.NavigateUri = navigateUri;
base.TargetName = "_blank";
base.OnClick();
}
}
Then use it like this:
private void ButtonSearch_Click(object sender, System.Windows.RoutedEventArgs e)
{
var hyperlinkwrapper = new HyperlinkButtonWrapper();
hyperlinkwrapper.OpenURL(#"http://www.google.com/#q=gocart");
}
I found that on this blog
couldn't test it right now but try:
HtmlPage.Window.Navigate(new Uri("http://www.bing.com/query?gocart", UriKind.Absolute), "_blank");
This should open a new browser window or tab with the url supplied... wouldn't expect any differences between Google and Bing in this regard.
The MSDN reference link is http://msdn.microsoft.com/en-us/library/cc190508%28v=VS.95%29.aspx
If you use google you can get html rendered results using Yahia's suggestion and open a link formatted such as this http://www.google.com/#q=gocart.
Out of the few api options I tried from the search api documentation I could only change the language without entering my API key.
(http://www.google.com/#q=gocart&hl=fr for French) Page result size etc failed but if you're looking for something quick and dirty with not much control the above will work.

Viewing an XPS document with malformed URI's in WPF

I'm trying to use DocumentViewer (or, more specifically, DocumentViewer's DocumentPageView) to load a presentation that was saved from Powerpoint as XPS.
However, the author of the slides was being clever and entered one of his URLs as a pseudo-regex (e.g. http://[blog|www]mywebsite.com). The built in XPS Viewer is able to load the document without a problem. However, DocumentViewer throws an exception because it tries to validate the URI:
Failed to create a 'NavigateUri' from the text 'http://[blog|www]mywebsite.com'
I could of course go into the slide and fix the URI so that the document displays. However, since I can't control the documents that will be used with my application, I'd prefer to find a way to display the document in spite of invalid URI's (like XPS Viewer).
Any thoughts?
The DocumentViewer is trying to create a Uri instance from the provided URL. If the URL isn't valid, the operation will fail.
You can prevent this from happening by performing validation on the URLs provided to you by the author.
(writing this without testing, so there may be some syntax errors)
public static bool IsValidUrl(this string url)
{
if(string.IsNullOrWhitespace(url) return false;
try
{
var uri = new Url(url);
return true;
}
catch
{
// if you were implementing IDataErrorInfo rather than using a
// lousy extension method you would catch the exception
// here and display it to the user
return false;
}
}

From Silverlight, generate file to save on user's computer without hitting server

I have a Silverlight app where I want to do an export of some data. The file output format is most likely going to be PDF or Word. But let's assume I can generate the file contents appropriately. I want to be able to pop up a Save dialog for the user to save this data or open it directly in the program.
Now obviously I could just launch the user to a URL and do the export on the server, and change the MIME type of the response to be either Word or PDF. This would work just fine. However, the sticking point is that I already have the correct data on the client (including complex filters and the like) and recreating this data set on the server just to send it back to the client again seems silly if I can avoid it.
Is there any way to take an existing set of data in Silverlight and generate a Word or PDF file and get it onto the user's computer? I could also do it from JavaScript using browser interop from Silverlight. I don't want to use out-of-browser Silverlight.
You need to use the SaveFileDialog class. Note that due to Silverlight's security settings, the SaveFileDialog needs to be opened as the result of a user event (e.g., a button click).
The dialog can be configured (if you want) using properties such as DefaultExt or Filter before you display it using the ShowDialog() method.
The ShowDialog() method will return true if the user correctly specified a file and clicked OK. If this is the case, you can then call the SaveFileDialog.OpenFile() method to access this file and write your data to it.
Example:
private void Button_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
if (saveDialog.ShowDialog())
{
System.IO.Stream fileStream = textDialog.OpenFile();
System.IO.StreamWriter sw = new System.IO.StreamWriter(fileStream);
sw.Write("TODO: Generate the data you want to put in your file");
sw.Flush();
sw.Close();
}
}

Resources