Click here to Skip to main content
11,584,288 members (61,567 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET file Text
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
Amit
Posted 26-Apr-11 3:36am
Comments
J a a n s at 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..
santosh.mail2011@rediffmail.com at 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 hosted..do u have any idea of that..?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
SAKryukov at 26-Apr-11 12:50pm
   
Correct, my 5. The question is ridiculous. Even on client side: who knows what the OP is?
--SA
SAKryukov at 26-Apr-11 12:56pm
   
OP might need just a text box. However, at the degree of confusion...
See my answer, anyway.
--SA
Oshtri Deka at 26-Apr-11 17:22pm
   
"And that is probably where your web server administration person is busy swearing at you..." :D
How true!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
Regards
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx[^].

—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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

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

  Print Answers RSS
0 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 329
2 Dave Kreskowiak 240
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,663
1 Sergey Alexandrovich Kryukov 1,229
2 Abhinav S 701
3 Dave Kreskowiak 667
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100