在Silverlight 4 Bussiness应用程序中打开记事本 [英] Open Notepad in Silverlight 4 Bussiness Application

查看:88
本文介绍了在Silverlight 4 Bussiness应用程序中打开记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Silvleright业务应用程序Silverlight_BussApp.
它具有Silverlight_BussApp项目和Silverlight_BussApp.Web项目.
在按钮单击事件的后面代码中填充记事本后,我需要打开一个记事本.
我不能使它成为浏览器之外的应用程序.
因此,由于silvlight不允许我这样做,因此我在Silverlight_BussApp.Web项目中创建了WCF服务
并通过Silverlight项目中的代理对其进行了调用.效果很好.
WCF服务中的代码为:

I have a Silvleright Bussiness Application Silverlight_BussApp.
It has the Silverlight_BussApp project and the Silverlight_BussApp.Web project.
I need to open a notepad after populating it in the code behind on a button click event.
I cannot make this an out of browser application.
So since silvlight 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;
            }
        }

现在,我需要在多个Silverlight项目中使用此openFile功能.
因此,我创建了WCF服务并将其托管在IIS上,并在Silverlight项目中创建了代理,然后
令我沮丧的是,该文件无法打开,并不断显示找不到文件"错误.
有人可以帮我弄清楚如何使它成为我所有Silverlight项目的可重用功能.
为什么当我在IIS上托管的WCF服务中使用相同的代码时却无法正常工作,为什么却不能正常工作
当托管在silverlight项目的同一解决方案中时.

Now i need to use this openFile functionality in more than one Silverlight Project.
So i created a WCF service and hosted it on the IIS, created a proxy in the Silverlight project and
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 fucntionality for all my Silverlight Projects.
Why is it when i use hte same code in a WCF Service hosted on a IIS does not work while it works prefectly
when hosted in the same solution of the silverlight project.

推荐答案

您要尝试执行的操作是不可能的.想一想. Web服务在服务器上运行.如果将Process代码放在Web服务中,它将尝试在服务器上打开记事本.

我什至也不确定您是否可以在Silverlight应用程序中使用Process对象.
What you''re trying to do is impossible. Think about it. A web service truns on the server. If you put the Process code in the web service, it''s going to try to open Notepad ON THE SERVER.

I''m not even sure you can use the Process object in a silverlight app, either.


这没有任何意义.而是将System.Windows.Controls.TextBox用于Silverlight,请参阅 http://msdn.microsoft.com/zh-cn/library/system.windows.controls.textbox%28v=vs.95%29.aspx [
It makes no sense. Instead, use System.Windows.Controls.TextBox for Silverlight, see http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox%28v=vs.95%29.aspx[^].

By the way, you can make much more comprehensive edit control out of it then the really lame Notepad. I have no idea why anyone would use such a rudimentary application as Notepad. Even the much needed indication of current cursor position is missing…

—SA


看看这篇文章:
从Javascript启动可执行文件 [ Silverlight of the Day#15 –在JavaScript和Java之间进行通信Silverlight [
Take a look at this article:
Start an executable from Javascript[^]

Call the javascript from SilverLight:
Silverlight Tip of the Day #15 – Communicating between JavaScript & Silverlight[^]

As long as you are in IE this is an option - highly insecure though... you probably need to alter the security settings of IE to make it work.

As SAKryukov mentioned System.Windows.Controls.TextBox is probably a better choice.

Best regards
Espen Harlinn


这篇关于在Silverlight 4 Bussiness应用程序中打开记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆