Assuming this is part of a web site (these are the ASP.NET forums) then are you having the problem on your development machine or after deploying to production? The process that serves your web pages would not, usually, have access to a users folder on
the server. Do you know what account your web server process runs under? Have you checked that this account has access to the file in question? Can you show your evidence as you may have got this wrong?
Are you aware that the code you have shown will run on the web server and not on the client computer? Does the user account actually exist on the web server? I ask, because this is a very strange setup. It is certainly not normal for A) a user to have
an account on a server and B) for a server process to write directly to a user folder.
aparitala
Member
13 Points
83 Posts
How to write text to notepad
Nov 14, 2012 07:12 PM|LINK
How to append text to notepad using in c#
I tried this but it doesn't works
File.AppendAllText(@"C:\Users\vanaajay_p.APOLLO\Desktop\Write.txt", count + "Files get deleted on" + System.DateTime.Now);
and
FileFile.AppendText(@"C:\Users\vanaajay_p.APOLLO\Desktop\Write.txt", count + "Files get deleted on" + System.DateTime.Now);
Ps: I need to append the text daily and i don't want to overwrite previous text in that notepad.
Can some one please help...
javedwahid
Participant
1687 Points
471 Posts
Re: How to write text to notepad
Nov 14, 2012 07:47 PM|LINK
What error are you getting? Are you sure that the program that is trying to write to the file has permissions to do so?
aparitala
Member
13 Points
83 Posts
Re: How to write text to notepad
Nov 14, 2012 07:59 PM|LINK
Hi,
Thanks for the reply!
No error. And yes, that text file has Write, read, Modify all permissions
javedwahid
Participant
1687 Points
471 Posts
Re: How to write text to notepad
Nov 14, 2012 08:16 PM|LINK
Have you run the debugger to see what happens when that line of code is executed?
Paul Linton
Star
13431 Points
2535 Posts
Re: How to write text to notepad
Nov 14, 2012 09:08 PM|LINK
Assuming this is part of a web site (these are the ASP.NET forums) then are you having the problem on your development machine or after deploying to production? The process that serves your web pages would not, usually, have access to a users folder on the server. Do you know what account your web server process runs under? Have you checked that this account has access to the file in question? Can you show your evidence as you may have got this wrong?
Are you aware that the code you have shown will run on the web server and not on the client computer? Does the user account actually exist on the web server? I ask, because this is a very strange setup. It is certainly not normal for A) a user to have an account on a server and B) for a server process to write directly to a user folder.
Sailaja Redd...
Member
452 Points
81 Posts
Re: How to write text to notepad
Nov 16, 2012 04:34 AM|LINK
Here is the sample set of code which appends text to the file without overwriting.
protected void btnSaveText_Click(object sender, EventArgs e) { string Filename = "C:\\Users\\Administrator\\Desktop\\Profile.txt"; if (!File.Exists(Filename)) { StreamWriter txtFile = File.CreateText(Filename); txtFile.Close(); txtFile = File.AppendText(Filename); txtFile.WriteLine(txtAboutYou.Text); txtFile.Close(); } else File.AppendAllText(Filename, txtAboutYou.Text); lblMsg.Text = "Text is saved"; }The code which you are using is fine and correct even.
Probably you might be creating file everytime using the following statements if I suppose
thats why the contents are overwritten.
if am wrong , kindly share your code , so that someone could help you resolve the issue.
Sailaja.
MyTechnical Blog
aparitala
Member
13 Points
83 Posts
Re: How to write text to notepad
Nov 19, 2012 08:24 PM|LINK
Sailaja Thank You...!