|
Every one of us has downloaded dozens of executable files from the Web, but for the life of me I can't find out how this is done. Every time you go to a commercial site that offers software for free or for sale, you can click on a download button and a standard dialog with the title, "File Download - Security Warning," pops up with Run, Save, and Cancel buttons.
What do you have to do to bring up this dialog? This obviously isn't a Silverlight-specific question, but searching the general Web forums mysteriously don't seem to answer this question, either. But I have to get this standard dialog coming up from my Silverlight app. If you could just point me to the right subject in a book somewhere, I'd be eternally grateful.
I know there are security issues about downloading executable files. Nevertheless it's done all the time, through this standard "File Download - Security Warning" dialog that is undoubtedly available through thousands of Websites. I don't understand why this seems to be such hidden knowledge. I have several books on Website development and there isn't a word about this in any of them. Where is it actually documented how to do this?
|
|
|
|
|
This shouldn't be difficult for someone whose been a programmer for as many years as you!
|
|
|
|
|
Richard Andrew x64 wrote: This shouldn't be difficult for someone whose been a programmer for as many years as you!
I've never done any Web programming. Silverlight is my first exposure to it. It's been desktop programming for me ever since I landed my first job that required development for a PC back in 1988. Now desktop programming is passé and I need a new career.
I went to the bookstore today and looked through a bunch of ASP.NET books and Website development books and couldn't find a single one that mentioned this standard "File Download - Security Warning" dialog. If you know the answer, please let me know what it is. Evidently I don't even know the technology that puts out this dialog, so I don't know what kind of a book to look in for the answer.
I also read about the Silverlight SaveFileDialog class, hoping it would give me something like what I need, but the examples I'm seeing are very confusing. I was hoping I would be able to get a Stream from a file on my Website and be able to call some function in the SaveFileDialog class that would let me feed that stream into a file I would browse to with the SaveFileDialog.ShowDialog method, and then save the file with that stream, but evidently that's not how it works. There isn't even a Save method in this class, only an Open method. The OpenFileDialog class has methods like Create and OpenWrite but they are restricted for internal use only.
All I want is hint of where to look to do the research. I don't even know what I should be studying.
|
|
|
|
|
I apologize for my sarcasm, but it seemed funny at the time.
As far as I know, the dialog box you're talking about is the duty of the browser to show.
The web server simply serves the file, with its associated MIME type being listed in the HTTP headers.
Now, if the browser sees that it is not a file used for rendering a web page, first it looks to see if it has a registered handler for that type of file. For instance, a WAV file would trigger the browser to launch Media Player.
If there is no registered handler for the specific type of file, then it would open the Save As dialog box.
|
|
|
|
|
I don't know Silverlight, but I would guess that it's probably up to you to implement and launch the Save As dialog box yourself.
When you want to download the file in question, open an HTTP connection to the URL, then once you have that, launch the Save As dialog box for the user to choose a location to save the file.
Then all you have to do is alternately read the network stream and write the file.
|
|
|
|
|
There is a SaveFileDialog class in Silverlight, but it doesn't do what you're speculative Save As dialog would do. I believe I have to read about Isolated Storage and the ways around it.
I believe I know how to download a System.IO.Stream from my Website. The problem then is saving that stream outside of Isolated Storage, which is a security violation. But there must be a way to ask to do that, which forces out the "Download File - Security Warning" dialog. I just have to figure out how to do that.
|
|
|
|
|
I'm not the expert on Silverlight, but I would suspect that the only way to break out of Isolated Storage is by installing your application as a full-trust app, which is not possible for a web application.
Read about the different trust levels, that may provide some clues.
|
|
|
|
|
I know that Websites successfully download executable files all the time. Any Website that sells its programs where you can download them right there on the spot does it. There's nothing special the user has to do to enter the Website. All they have to do to get the download is to go through the "Download File -- Security Warning" dialog.
Maybe there is no way around it if all your Website programming is in in the Silverlight app, which runs on the client. But Silverlight doesn't have to be the whole site. It can just be part of it. I have developed a commercial desktop program that I want to sell through the Web, and I have contracted a Website developer that is doing the bulk of the Website programming for me (since I'm out of my league there). He can't figure out how to download my installation program, which we've uploaded to the Website itself. He says he's "still working on it." I was just fishing around up here to see if anyone had any ideas.
Turns out I was probably asking the wrong question. Unfortunately, I still don't know what the right question is.
|
|
|
|
|
Well let's be clear, it's not the website that's downloading the file when you purchase a program over the net.
It's the user and his browser who is downloading the file. That's why the system allows you to save the file anywhere you want, because it's you doing it.
On the other hand, your Silverlight app is restricted in where it can save files because it's not under the direct control of the local user, and it could very well be malicious. ( Not that yours is malicious, just saying...)
Maybe there is a way you can have your app direct the browser itself to the URL from which it can download the file, and that would provide the functionality you seek.
|
|
|
|
|
This isn't a Silverlight problem. I have to put a regular HTML page behind our Silverlight Download button.
|
|
|
|
|
Maybe I'm looking at this the wrong way. Maybe the "File Download - Security Warning" dialog is coming directly from the Windows operating system because you're trying to write a file to the local machine from a Web browser. So maybe my question should be, how do I write to a file outside of Isolated Storage? Once I know how to get around the security issues that prevent that, the "File Download" dialog will be produced automatically. Please let me know. Am I on the right track? I just need some guidance here.
|
|
|
|
|
I can tell with some certainty that that dialog box is coming from the browser, as evidenced by the fact that Firefox has its own version of it which is different from IE's version.
As I said above, read about trust levels.
|
|
|
|
|
This is achieved by the use of Mime types and is very easy to do. Consider the following sample ASP.NET page
:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="~/googletoolbar2user.exe" runat="server">Exe</a>
</div>
</form>
</body>
</html> Clicking the link when it's running prompts the browser to display the warning you're after. Have a look at this post[^] to see more information on what you need configuring in IIS. There's no special voodoo, and I'm not surprised that books on ASP.NET don't teach this as it's more about general web development rather than Silverlight/ASP.NET issues."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
So in otherwords, behind our Silverlight Download button, we have to put a regular HTML page like your example. Now it's making a heck of a lot more sense. Shows how ignorant I am of this entire world of Web programming. Thanks a lot. It probably sounds incredibly basic to you, but all this is entirely new to me, so new that I don't even know how to pose the right questions.
|
|
|
|
|
Maybe im being silly but the simplest solution I can think of is to embed the silverlight in a HTML page which this javascript function:
function redirect(url){
window.location=url;
}
and then call that JS from silverlight with "http://domain.com/file.exe".Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
We've already got a fairly elaborate Silverlight app. So without refactoring the entire design, we have to work from Silverlight to HTML, not the other way around. I'm thinking of taking a rather crude approach: HtmlPage.PopupWindow, with the URI parameter to PopupWindow pointing at the HTML page that downloads the executable. If there's a more elegant solution someone could suggest (I'm sure there must be), I'd be grateful to receive it.
|
|
|
|
|
Well, you can set the URI straight to the exe to popup the download window. Therefore skipping the extra HTML page. Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
|
Hi,
I'm working in a silverlight aplication.
In the web project I built a domain service after create a ADO entity model. In the client project i can invoke the web project service methods.Everything is fine here.
But, now i add just a domain service(in the web project) and defined some methods here.The problem is when i try to access this methods in the cliente project. I can instantiate the service and invoke the method but it does not anyting. Do i have to give some special treatment when i call the service methods on the client project?
(Excuse my english but i do not speak it very weel )
thanks. regards jonatan
|
|
|
|
|
I'm developing a WPF Facebook application, and I was wondering whether there is any way that I can persist login information, so that users don't have to repeatedly type in their passwords everytime they want to view photos etc. Or lets say I have a bunch of passwords stored in a database, how can I log in to Facebook using that specific password without the user having to type it in?
I'm using the following to create a session:
session = new DesktopSession("[app key]", null, null, true,
new List<Enums.ExtendedPermissions>() { Enums.ExtendedPermissions.read_stream, Enums.ExtendedPermissions.publish_stream });
session.Login();
|
|
|
|
|
Hello everybody,
I have added a new xaml page in my silverlight project, but I don't know how to host it into a new aspx page rather, how do I do that? What I mean is I'm trying to have multiple silverlight(xaml) pages in one project and hosting them in different aspx pages.
Thank youmodified on Tuesday, February 23, 2010 7:55 AM
|
|
|
|
|
|
Hi there,
Hoping someone can help me with some issues I am having printing custom WPF controls. I have custom publishing application with a lot of WPF Custom Controls which host other Custom Controls - I would like to print these controls to XPS (or ideally PDF) so that they can be sent to a print house to be printed. The ideal format for me would be PDF, although in theory I should be able to convert XPS to PDF with the myriad of applications out there (currently I've used PDFCreator, Ghostscript, gDoc, PDFsharp, to name a few). I also use lots of render transforms and layout transforms to position visuals and control their size and orientation.
My main requirement is that the output file is a vector image and not a bitmap. Print media requires very high quality files, or the result looks awful!
The questions I'm hoping the smart members of the CodeProject can help me with are:
1. Has anyone done some preprocessing on a tree of Custom Controls and somehow converted them to more primitive WPF drawing components, like paths and formatted text? (This will help remove the dependency on the data).
2. Is there a way to create an XPS file well so that large amounts of image data are converted by PDFsharp (or similar) properly?
There are two approaches I've tried, each with its own set of problems:
1. Write the custom control as a Visual to an XPS fixed page document. Then convert to PDF using PDFsharp or PDFCreator.
2. Render the custom control to a high resolution bitmap, place the Image in a Canvas, create an XPS document, then convert to PDF. (My reason of not creating a PDF file directory, is that I would like to overlay other WPF controls on top of the bitmap, if possible). I'd like to avoid this.
The problems I've come across for each are:
1. Custom controls written to XPS file
a. Not all of the controls are rendered properly in the XPS viewer.
b. Strangely, if I print to PDF using PDF Creator from the XPS viewer, the controls that didn't display before get magically printed to the PDF file as bitmap images.
c. Bitmap images display in the XPS viewer, but don't convert to PDF (even though the image stream is inside the PDF file with bounding boxes!).
2. Render to high resolution bitmap
a. I lose the vector data, so I need to make sure the resolution of the output image matches the printing device and could result in odd edge and aliasing artifacts.
b. PDFsharp seems to think an Image in a Canvas is like a bitmap pattern. Why is it doing this? Any ideas on how to write a single image (without tiling) to a XPS file?
c. Writing the image directly to a PDF file is very easy, but this isn't what I want to do. I need to overlay the image with WPF Custom Controls.
Is there some way to open a RenderContext and then "render" the contents to a DrawingVisual?
Could this be a serialization issue in one of the classes my Custom Controls reference? I have vague recollections that these get obfuscated and stored inside the XPS file?
I'll be really indebted to anyone who could help. I'm really hoping there is a simple-ish way to do this. It could even by something like implementing some interfaces in my controls that allow WPF to traverse the nested Custom Controls, or to try to strip out all of the internal visuals. Or to make the WPF printing process use the Visuals inside my Custom Controls directly, rather than needing bound data. Or there is a way to do this using the framework and it's yet another wing of WPF to explore!
Many thanks
Mark
p.s. I have one final constraint: I can't buy any 3rd party components, so the "ultimate XPS to PDF converter" component that you may have would not be an option for me! For this project, I need to be cheap and write my own code.
|
|
|
|
|
How I get Application_Exit Eventhandler in javascript code....
I mean when Application_Exit Eventhandler fires how I notify in
javascript
modified 9-Jan-13 15:35pm.
|
|
|
|
|
Hi Kashif,
You can call any JavaScript function on your page like so:
void Application_Exit(object sender, EventArgs e)
{
HtmlPage.Window.Invoke("OnSilverlightExit", new[] { "some data" });
}
Here we see that the JavaScript function OnSilverlightExit is called and is passed a string parameter "some data".
The JavaScript function can then do whatever you need.
function OnSilverlightExit(identifier) {
}
There's some more information here[^] about communicating between a page in JavaScript with a Silverlight application.
Cheers,
Daniel
|
|
|
|
|