Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
            }
        }
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.
Posted

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.
 
Share this answer
 
Comments
Learning_abc 3-Aug-11 16:31pm    
@John Simmons,

I agree with you. I only thought if i could put it in WCF Project i would be able to open a notepad. This sucks big time becasue Microsoft has failed to provide the most required functionality.
Do you have any other work arounds as to how to open notepad in Silverlight?
Sergey Alexandrovich Kryukov 3-Aug-11 18:24pm    
No! The whole idea is wrong. Please see my solution.
--SA
Sergey Alexandrovich Kryukov 3-Aug-11 18:24pm    
My 5. I suggest the alternative.
--SA
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
 
Share this answer
 
Comments
Espen Harlinn 3-Aug-11 18:36pm    
Good advice :)
Sergey Alexandrovich Kryukov 3-Aug-11 18:44pm    
Thank you, Espen.
--SA
Learning_abc 4-Aug-11 9:39am    
Well the users that i work with would not be very happy about throwing away the Notepad. but i also need to be able to open an Existing Excel,Adobe files too along with the existing notepad files?
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-11 18:45pm    
Useful advice, but the most important part of it is your warning against using this approach. My 5.
--SA
Espen Harlinn 4-Aug-11 3:54am    
Thanks Sergey!
Learning_abc 4-Aug-11 9:41am    
I tried the ActiveXObject but it is highly unsecure. So is making my application an out of browser app the only solution to be able to open existing Excel, CSV, Notepad application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900