Click here to Skip to main content
15,611,422 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi all,
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

System.Diagnostics.Process.Start("notepad.exe", "Filepath");

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
J a a n s 27-Apr-11 23:58pm    
Why you need to open these files in notepad? You can provide a page where the user can edit and save the files using textarea or so.. 11-Dec-12 4:14am    
i have to host the website on a pc and run it on another client machine and want to open the notepad of client machine...the above code will open the notepad of the machine on which web application is u have any idea of that..?

It's quite simple.

Client: runs javascript, shows HTML via browser.

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.
Share this answer
Sergey Alexandrovich Kryukov 26-Apr-11 12:50pm    
Correct, my 5. The question is ridiculous. Even on client side: who knows what the OP is?
Sergey Alexandrovich Kryukov 26-Apr-11 12:56pm    
OP might need just a text box. However, at the degree of confusion...
See my answer, anyway.
Oshtri Deka 26-Apr-11 17:22pm    
"And that is probably where your web server administration person is busy swearing at you..." :D
How true!
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.
Share this answer
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?
Share this answer
The idea of using Notepad 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 System.Web.UI.WebControls.TextBox, see[^].

Share this answer
leave the .exe offthe end of notepad
System.Diagnostics.Process.Start("notepad", "Filepath");
Share this answer

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