In Silverlight, is there a way to launch a generated file while running inside a browser?
In a normal HTML browser, if I click on a link to a file, I get the option to save or run it.
In Silverlight I can generate a file, and save it using the following code:
SaveFileDialog sfd = new SaveFileDialog { Filter = "MyFileExt files (*.myFileExt)|*.myFileExt" };开发者_JAVA百科
Stream stream = sfd.OpenFile();
StreamWriter writer = new StreamWriter(stream);
writer.Write(myFileString);
writer.Flush();
writer.Close();
sfd = null;
Is it possible to prompt the user to open this file, so that they don't have to open up Windows explorer, look for the file and double click it?
Short answer: no, that's impossible.
Explanation: Silverlight is a client side technology so possibility to access local computer might be serious security breach (just remember ActiveX and all those security troubles connected with it).
One way to launch something from your local computer using Silverlight is launch your SL 4 (unfortunately only SL 4 supports all this stuff) application out-of-browser with elevated trust. In that case it's possible to use COM to access file system and launch applications.
For example:
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
shell.Exec("calc");
}
精彩评论