473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

StreamWriter problem

I want to open a new file and keep on appending the text
depending on some condition.

I have used this code but it is not appeneding properly

It is giving some numbers in the output file
if(index=="3")
{
files=new FileStream
(filetext1.Text+"\\"+tgname+"\\"+"GlobalDeclaratio ns"+".cs"
,FileMode.Append,FileAccess.Write,FileShare.ReadWr ite);

swriter=new StreamWriter(files);

if(san==0)
{

swriter.WriteLine("using System;");

swriter.WriteLine("using System.IO;");

swriter.WriteLine("namespace "+ " "+tgname+"\r\n"+"{");
swriter.WriteLine
("public class GlobalDeclarations"+"\r\n"+"{");
}

}
swriter.WriteLine(rtb2.Text);
swriter.Close();
}
Where am i going wrong?

Please say me

Thank you.
Jul 21 '05 #1
4 1751
Vannela <an*******@discussions.microsoft.com> wrote:
I want to open a new file and keep on appending the text
depending on some condition.

I have used this code but it is not appeneding properly

It is giving some numbers in the output file


What do you mean by "it is giving some numbers in the output file"?
Please give a short but complete program which demonstrates the
problem, describing exactly what you expected to happen and what did
happen.

See http://www.pobox.com/~skeet/csharp/complete.html for more of what I
mean by this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
What actually i want is when the index is some value (for
example 2 or 5)which i want then the text in the rich text
box of my form should get append to the file, if the file
exists or create a new file if it does not exists ?

And once the file is created if the condition is true ie.,
if the index value is 2 or 5 then the text in the rich
text box should get appended to the file created.

My code is as follows

if(index=="2" || index=="5")
{

files=new FileStream
(filetext1.Text+"\\"+tgname+"\\"+"GlobalDeclaratio ns"+".cs"
,FileMode.Append,FileAccess.Write,FileShare.ReadWr ite);

swriter=new StreamWriter(files);
swriter.WriteLine(rtb2.Text);
swriter.Close();
}
But the output i am getting is somthing like this

000000000 75 73 69 6E 67 20 53 79 73 74 65 6D 3B 0D 0A
75using
000000010 74 69 24 24 44 44 3D 43 48 4F 0D 3B 0D 2E 6D
System
.................................................. ..........
.................................................. ..etc
in this way

What could be the problem

-----Original Message-----
Vannela <an*******@discussions.microsoft.com> wrote:
I want to open a new file and keep on appending the text depending on some condition.

I have used this code but it is not appeneding properly

It is giving some numbers in the output file
What do you mean by "it is giving some numbers in the

output file"?Please give a short but complete program which demonstrates theproblem, describing exactly what you expected to happen and what didhappen.

See http://www.pobox.com/~skeet/csharp/complete.html for more of what Imean by this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Jul 21 '05 #3
Vannela <an*******@discussions.microsoft.com> wrote:
What actually i want is when the index is some value (for
example 2 or 5)which i want then the text in the rich text
box of my form should get append to the file, if the file
exists or create a new file if it does not exists ?

And once the file is created if the condition is true ie.,
if the index value is 2 or 5 then the text in the rich
text box should get appended to the file created.

My code is as follows

if(index=="2" || index=="5")
{

files=new FileStream
(filetext1.Text+"\\"+tgname+"\\"+"GlobalDeclaratio ns"+".cs"
,FileMode.Append,FileAccess.Write,FileShare.ReadWr ite);

swriter=new StreamWriter(files);
swriter.WriteLine(rtb2.Text);
swriter.Close();
}
No, that's *part* of your code. Please post *complete* code. Did you
read the page I posted a link to?
But the output i am getting is somthing like this

000000000 75 73 69 6E 67 20 53 79 73 74 65 6D 3B 0D 0A
75using
000000010 74 69 24 24 44 44 3D 43 48 4F 0D 3B 0D 2E 6D
System
.................................................. .........
.................................................. .etc
in this way

What could be the problem


When you say "the output you are getting is", do you mean that's the
whole output of the file? Was there a file there before? What were you
expecting to get differently?

Please post enough information so that I (or someone else) can fully
reproduce this, with exactly what you expected to happen and what
happened differently. Currently you're leaving us guessing.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
I could not read the site you specified b'coz the access
is denied for that site in our college.

When i say output i mean the text in the file ie., the
whole output of the file.

The file is being created when the condition satisfies for
the first time , and from the second time onwards the text
in the richtextbox of form should get appended to the file
created.

But i thing the problem is somewhere in the creation of
the file because if the condition is satisfying only for
one time then the output of my file is correct ie., i am
getting the output what i am expecting. But if the
condition is satisfying for more than one time then i am
not getting the correct output.

rtb2.Text is the text in the richtextbox which i want to
have in the file GlobalDeclarations.cs

filetext1.Text="d:\santhu\projects\current\PB8.0";
tgname="cd_core";

if(index=="2" || index=="5")
{

files=new FileStream
(filetext1.Text+"\\"+tgname+"\\"+"GlobalDeclaratio ns"+".cs"
,FileMode.Append,FileAccess.Write,FileShare.ReadWr ite);

swriter=new StreamWriter(files);
if(san==0)
{
swriter.WriteLine("using System;");
swriter.WriteLine("using System.IO;");
swriter.WriteLine("namespace "+ " "+tgname+"\r\n"+"{");

swriter.WriteLine("public class
GlobalDeclarations "+"\r\n"+"{");
}

swriter.WriteLine(rtb2.Text);
swriter.Close();
}






No, that's *part* of your code. Please post *complete* code. Did youread the page I posted a link to?
But the output i am getting is somthing like this

000000000 75 73 69 6E 67 20 53 79 73 74 65 6D 3B 0D 0A
75using
000000010 74 69 24 24 44 44 3D 43 48 4F 0D 3B 0D 2E 6D
System
.................................................. ...... .... .................................................. .etc
in this way

What could be the problem
When you say "the output you are getting is", do you mean

that's thewhole output of the file? Was there a file there before? What were youexpecting to get differently?

Please post enough information so that I (or someone else) can fullyreproduce this, with exactly what you expected to happen and whathappened differently. Currently you're leaving us guessing.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Hansen | last post by:
I am having a very strange problem with StreamWriter and writing to files. I have a procedure that is called several times to write out seperate files, each of them uniquely named by date all they...
1
by: Lars Hansen | last post by:
Hi This is probably pretty basic, but I have a problem with the access-level (local variable), when creating a new StreamWriter. I am trying to write some price information to a textfile - which...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.