Navigation error - c#

I have a hyperlink button in my Silverlight 4 application. I want to download an apk file when I click on this link. I am able to download file but my problem is that when I click on link it downloads the file and trie to navigate on that link so it shows the dialog for file download and raises an exception.
and the code behind hyperlink button is
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}
I just want to open the download link - not actually navigating to that page.

Set the URI within the markup:
<HyperlinkButton x:Name="MyButton" TargetName="_blank" Content="Download APK" NavigateUri="/download/ItimHRMSAndroidApp.apk" Canvas.Top="40" Canvas.Left="30"></HyperlinkButton>
And remove the Click event handler:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}

Why not try using a Generic Web handler
And return the apk file
Like this post
Hope this helps.

the problem was not of the _target field. it is of the path.

Related

Trying to use the "launch url on c#" but doesnt work

read title
Here is the code i'm using
System.Diagnostics.Process.Start("My url, dont wanna show it xd");
But visual studio tells this
screenshot
i tried using the light, but tells
this
You need to add a method to the click event before you can call the Process.Start. For instance:
button14.Click += Button14_Click;
Now if you click the button it will open the browser.
private void Button14_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("my url");
}
Have you tried
Process.Start("chrome.exe", "http://www.YourUrl.com");
Similar question here: How to launch a Google Chrome Tab with specific URL using C#

How to open links in wpf webview in default explorer

My webview display a html page which contains lots of links, if I click the link, the new page will open in the webview, is there a way to open the link in default browser rather than in webview?
You can handle the WebView.NavigationStarting event as follows:
private void navigationStartingHandler(object sender, WebViewNavigationStartingEventArgs e)
{
e.Cancel = true;
Process.Start(e.Uri.ToString());
}
Here and here are more answers about opening web pages in default browser

C# Intercept Browse Button

Have a unique customer request which Im unsure how to tackle.
The customer has a webpage form with a browse button to select a file. When the browse button is clicked, instead of showing the local files, they want to pop-up a window with a textbox to enter a code. This code is then used to select a file from a local folder containing 1000 files each with their own code. They want to prevent the user from viewing the other files in that folder.
I did write a custom Windows form to mimic the webpage form but they already have the webpage online and would like to reuse it.
Any ideas how to intercept the browse button? I can use a C# Application with the web browser component, but can that intercept the browse button?
The only option that I can see working is using a C# Application with the web browser component. You can then use WebBrowser.ObjectForScripting to provide a method that can be called to trigger your custom picker window through Javscript, e.g:
window.external.ShowPickerWindow();
You then have two options:
Interrogate the DOM of the page once it's loaded and replace the button with one that triggers your picker window.
Have the customer change their page so it checks for the existance of a window.external.ShowPickerWindow method and basically does option (1) for you.
You can then have a method, perhaps called window.external.GetPickedCode() to pull the code out in the page.
Rob kinder steered me along the correct thinking track by saying "replace the button" which has lead me to a solution which works beautifully!
In short, I hide the browse button, insert a new button next to it that when clicked, opens a new window with a textbox. This textbox then sets a string value in the parent form which is used onSubmit to attach the file.
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement btnBrowse = wb.Document.GetElementById("fiPhoto");
if (btnBrowse != null)
{
HtmlElement newbtn = wb.Document.CreateElement("input");
newbtn.SetAttribute("id", "btnLoad");
newbtn.SetAttribute("type", "button");
newbtn.SetAttribute("value", "Load");
newbtn.Click += new HtmlElementEventHandler(newbtn_Click);
btnBrowse.Parent.AppendChild(newbtn);
btnBrowse.Style = "display:none";
}
HtmlElementCollection forms = wb.Document.Forms;
if (forms.Count > 0)
{
HtmlElement form = wb.Document.Forms[0];
form.AttachEventHandler("onsubmit", delegate(object o, EventArgs arg)
{
FormToMultipartPostData postData = new FormToMultipartPostData(wb, form);
postData.AddFile("photo", photo);
postData.Submit();
});
}
}
private void newbtn_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.ShowDialog();
}
FormToMultipartPostData is too big to post in here but it basically manually constructs the Content-Disposition to be posted
Don't show the actual file browser, imitate one which is showing only that one file in in.
Or since you know the file path when correct code is entered copy the file to temp folder you created and open file browser to browse that folder and it will be contain only that file.

Way to detect event on folder

Work on C# .In one of my application I need to upload file and save to database.I write a button event
private void btnUpload_Click(object sender, EventArgs e)
{
}
After button click from user defined folder path I upload file,than rest of the syntax save in database.I have done above. Now I need to know, if a file save or update or on file if user do any type of action than I need to upload that file automatically.How to automatically active any event ,plz don’t say any type of timer event.As soon as user update file I need to upload it.How can I detect user update file?How can I active event to upload the file?If have any query plz ask.Thanks in advance.Any type of suggestion will be acceptable.
You can monitor the folder using FileSystemWatcher
You can use the FileSystemWatcher. Create a new instance like that:
var fileSystemWatcher = new FileSystemWatcher(fileToWatch);
fileSystemWatcher.Changed += OnFileChanged;
And in following event you can do the upload of the file:
private void OnFileChanged(object sender, FileSystemEventArgs e)
{
// Upload e.FullPath;
}

Windows phone7: Open a webpage on button click?

I just searched, but didn't find a way to create a web link in my Windows phone7 Application. In Android TextView has android:autoLink='Web' In Windows phone7 textblock I didn't find any relevant property.
Tried adding the NavigateURI property in the Hyperlink and it gives an exception. NavigateUri="http://www.google.com"
Really appreciate If someone Can suggest How to do this. Thanks in Advance...!!!!!
Use just the HyperLinkButton Control.
And add this property to your control:
<HyperlinkButton TargetName="_blank" Content="Go To" Click="HyperlinkButton_Click"/>
Finally add the click event handler to launch the browser using the BrowserTask :
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.google.com");
webBrowserTask.Show();
}

Categories

Resources