开发者

Open Notepad from Silverlight 4 Business Application

开发者 https://www.devze.com 2023-03-25 12:46 出处:网络
I have a Silvleright Business Application, Silverlight_BussApp. It has the Silverlight_BussApp project and the Silverlight_BussApp.Web project.

I have a Silvleright Business Application, Silverlight_BussApp. It has the Silverlight_BussApp project and the Silverlight_BussApp.Web project.

I need to open Notepad after populating it in the code behind on a button click event. I cannot make this an out of browser application.

So since Silv开发者_Python百科erlight does not allow me to do it, I created a WCF Service in the Silverlight_BussApp.Web project and invoked it through a proxy in the Silverlight Project. This works fine. The code in the WCF Service is:

  public void openFileWithNotepad(string filename)
        {
            try
            {
                if (File.Exists(filename))
                {
                    Process.Start("notepad.exe", filename);
                }
                else
                {
                    MessageBox.Show(
                           "I was unable to locate the following file: " + filename,
                           "File Not Found");
                }

            }
            catch (Exception e)
            {
                throw e;
            }
        }

Now I need to use this openFile functionality in more than one Silverlight Project. So I created a "WCF service Project" and created a WCF Service, hosted it on IIS, and created a proxy in the Silverlight project. To my dismay, the file does not open and it keeps giving me the "File Not Found" Error. Can somebody help me figure out how I can make this a reusable functionality for all my Silverlight projects?

Why is it when I use the same code in a WCF Service hosted on IIS it does not work while it works perfectly when hosted in the same solution of the Silverlight project?


For starters, the code in the Silverlight_BussApp.Web project is going to be executed on the server, while the code in the Silverlight_BussApp project is going to be executed on the client. During development, the client and the server are ostensibly the same machine -- when you click "Run" in Visual Studio, a development web server starts up on your machine and hosts your .Web project, while the Silverlight application runs in your browser.
When your application is deployed, the client (i.e., your browser) will most likely be on a different physical machine than the server (i.e., IIS). So, ignoring any other security restrictions that may be imposed by IIS (which is probably why you're getting a "File Not Found" error), the call to Process.Start would start Notepad on an entirely different machine than the one you're using.

Try using a SaveFileDialog to save whatever you want to the client's machine, then tell them to open the resulting file.

0

精彩评论

暂无评论...
验证码 换一张
取 消