Open a file in the browser from Silverlight - file

I have a Button (or a hyperlinkbutton) in Silverlight. I want to open a file on a server share when this butto in clicked. With other words I want a new Browser Tab or Window to open showing the requested file, just like I enter the URL in the browsers addressbar:
file://C:\myfile.txt
I tried in the OnClick Method the following:
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(#"file://C:\myfile.txt"),"_blank");
it throws an Exception (Access denied).
When I do the same with an http: page it works:
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(#"http://www.somedomain.com"),"_blank");
How can I achive the same with a file. Security can not be an issue, I have full access to that file. And please don't tell me that this is not possible... would mean we have to go back to PHP.

Silverlight runs on the client side and in by default in LOW trusted mode which dont allow application to access local file system.
For the purpose, u can try giving full trust to the silverlight application.

Firefox does not allow external URLs to link to a local resource anymore :(

Related

Access Specific PDF Page in WPF WebBrowser Control

I have a webbrowser control in my application that is used to display pdf files that have been created in iTextSharp and are stored locally on the hard drive.
I would like to be able to navigate the file (next, previous, first, last, toc) from my application rather than using the inbuilt nav of the reader in the browser.
I have seen that you can navigate to specific pages by using
Browser.Navigate("filename.pdf#page=?);
This works the first time but when trying to navigate to a different page, it makes the browser disappear completely with no errors. However, I can reload the file without problem if I don't have the #page=? suffix on the file url though. Any ideas on this?
Alternatively, is there anyway in iTextSharp of adding something to the file to allow for it to be navigated from an external command?
All the official parameters that can be used to navigate through a PDF using parameters in the query string after the ? character are listed in a document published by Adobe: Parameters for Opening PDF Files
You already mentioned the page parameter. Another option could be using named destinations: nameddest=destination. In this case, you need to add the anchor with name destination to the file using iTextSharp.
Note that not all viewers implement these parameters. Adobe supports them in Adobe Reader and in the Adobe Reader plug-in, but there is no guarantee that they will work in pdf.js (Firefox), Pdfium (Google Chrome),... If your browser disappears when using an open parameter, you may have hit a bug in the browser or the viewer plug-in that causes the browser to crash. iTextSharp nor iText can crash a browser ;-)
There are no other ways you can navigate a PDF from an external application. The only thing you can do, is to add JavaScript to the PDF so that it always opens at the same page. This is done using an open action. I don't think this solves your problem as it would mean that you have to change the PDF file every time you want it to open at a different page.

IE file download box get location

i am currently working on a issue where i need to get location of the file downloaded.First let me explain the scenario.
I placed a link in my page and when user clicks the link it shows file download dialog with open/save/cancel options in IE.Now when the user clicks on the save button and choose a location to save the file i need to get that file saved location using whatever options possible.
Thanks!
I do not think you can... at least not easy. This runs on the client, and for security reasons you can not acces the client's filesystem with javascript.
Maybe it is however possible using a flash or silverlight plugin, as the user can allow access from within these applications to the local filesystem. It might be very difficult tho...
The browser will not allow you to access information about the clients filesystem.

SILVERLIGHT. How to download file like from web-site

I want download file from server. I know how to do this using WCF/RIA services. How can I do this like in web site. For example: I click button and It will appear standard dialog browser window to download file.
Use the Hyperlink control and link it to a server-side URL. This is what I've done in my app to avoid the whole generic save file prompt restrictions of the default SL sandbox.

C Sharp DEvelopment of Windows Forms Application

I'm developing a Windows Application in C sharp.using a Web Browser control to Login to the Https Site and Download the List of files. I'm able to login in to the Site and I'm able to Navigate to the Page where files are listed to be downloaded. When I try Downloading the file using the file URL and trying to Navigate using Web Browser Control a Pop - Up appears asking whether to Open or Save or cancel. How to handle this Pop up and I'm stuck here.
Any Answers are appreciated.
Thanks,
Vinay.
If all you are trying to do is download a file, you might be better off using webRequest.Create("Url") instead of the WebBrowser control. There are ways of handling authentication depending on the method the website uses.
It's best not to use the WebBrowser to download files (unless initiated by the user, who can click the save button). Instead, you can use a WebRequest to download the files from your application.
Since you said you have to log in to the website, I'm going to assume that it uses the popular method of using cookies (as opposed to HTTP Basic Auth). To get the cookies from the WebBrowser, you can use the Cookie property of the WebBrowser's Document property.

How do I access the existing running windows forms application through url?

I have a windows forms application and which provides a way to search the database based on the provided value. Sometime I need to open the application through a simple html hyperlink with the search result while loading itself. There are two questions/doubts from here.
How to access the existing running windows forms application as url? If this is possible, how can I pass the argument?
If the application is not running, we have to start the application and search the value. This also has to be happened when I click the link.
Simply we can say like, if you open a website link from your outlook email, the link will be opening in existing opened default browser or it will start the new browser(if the browser is not already opened.) I want to achieve the same behavior.
Seems to be the below post is somewhat related to my queries, but this does not solve my problem.
Activate existing browser window with given URL from C# application (without triggering reload)
You can't do this. The default browser launches when you click on a link because it is set up in the registry as the default handler for hyperlinks.

Resources