I have been developing a website where the requirement is to open .txt, .xml, .config files in notepad where I can edit the same and save at its original position.
I have tried with
but when the project is deployed the same code is unable to open the file for editting purpose.
Please suggest a solution to my problem.
Thanks in advance
It's quite simple.
Server: runs C#, sends HTML to client.
When you execute Process.Start on the server, it executes on the server. And that is where Notepad will open. And that is probably where your web server administration person is busy swearing at you...
It worked on your PC prior to deployment because the client and server were the same machine, and you didn't notice.
If you are developing a website you cannot access the notepade.exe file as it is a security risk, well there are ways of getting around this, but this is a bad practice.
What you should rather do is upload the file you want to edit to the server, then open it within the webpage, and then allow the user to make changes and then let the user download the file to thier computer.
Please note that if you are going to load the txt, xml file to the browers you will need to check for CSS (Cross site scripting) hacks and other bad "text".
Hope this help.
The idea of using
is totally ridiculous; see how Griff explained it.
Even if you think you can open any client-side application (using ActiveX, for example), it would be equally ridiculous: you can never assume your client use Windows or any particular application is available.
Instead of using any editor you can use
, see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx
offthe end of notepad
Ideas to try (with a gut feel that if this is a web site as you say, the problem is somewhere in 1.):
1. You say this is a web site - is your problem with code running client side or server side? Is the file stored on the client or the server? To be viewed on the client or the server? Using ASP.NET? If client side, what .NET code do you have running on the client? If server side, are you in IIS? If so, how does the user interact with a file opened server side? Does IIS even have permission to interact with the server desktop? You imply things work when you are in your development environment - but could this be hiding the real problem if client and server are then actually the same machine? Are you relying on Notepad being able to open a file over the web using HTTP? And what if the client computer isn't running Windows at all? If any of this is the issue, you might have to abandon Notepad and go for something like a web page with a Form / Textarea.
2. Put try / catch block and some logging of any exception round that line of code - at least it might give you a clue you what's failing.
3. Check the obvious - Notepad is actually installed on the relevant computer (Start / Run / Notepad works?).
4. Is this a code permission issue? Does the code have / need Full Trust (or more trust than it has)?
5. Does the user (or server account the code is running in) have file (or HTTP) access permissions for the file you are trying to open?
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)