Showing posts with label saving. Show all posts
Showing posts with label saving. Show all posts

Monday, March 26, 2012

Text files, reading,writing and saving

Hi,

I want a textbox on my site, you write in it and click save

the text is then saved as 'sample.txt'

then I also want that page to OPEN 'sample.txt' and read the contents into a textbox

I just want the simplest way of doing this

can someone point me at the code

thanks

Seethis tutorial which does what you ask.

yes, that answered it

thanks!


AHHH... looks like the right code however...

got a couple of textboxes and buttons

I pasted this code from the tutor into the code area of a button

System.IO.StreamReader StreamReader1=new System.IO.StreamReader(Server.MapPath("test.txt"));TextBox2.Text= StreamReader1.ReadToEnd();StreamReader1.Close();
it says: streamreader is a type in IO and cannot be used as an expression
it also says streamreader is not declared.
im using basic not C is that the problem?

Yes, the tutorial is in C#, not VB. For a VB tutorial trythis page.

yes the code example is written in C

however im using basic

visual web developer express

anyone know how to read write and save a file ...simply

it seems as though I can't use streamreader...there is no help on it in web developer express.


thanks for your help.Geeked

To read.. there's a great new addition to the System.IO namespace and that's "ReadAllText"

So you'd say

Text1.Text = System.IO.File.ReadAllText(Server.MapPath("~/sample.txt"))

and that's it!

For writing, the above links that everyone else is fine... 3 lines using the StringWriter class... and never ever forget to ".Dispose" the object otherwise it will lock the file


You've probably worked this out by now , but I wrote a little tutorial the other day that does exactly this, it over here if you're still intrestedwww.codeproject.com

Thursday, March 22, 2012

Textarea to sql 2000 text datatype

Hi All,
Does anyone have any example of asp.net code for saving a
textarea into a text/ntext column in sql table?

thanks

slyiShouldn't be any different to storing any other type of data.
Are you having problems testing this normally?

Just create a Stored Procedure to do it, and set the parameter.
Worked for me

HTH

My Example:

*****************
Sql
******************

CREATE PROCEDURE [spname]
@.MyNTextParam NTEXT
AS

INSERT INTO MYTABLE VALUES(@.MyNTextParam)

*************
c#
*************

SqlCommand cmd = new SqlCommand([spname], [connectionstring]);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.add(new SqlParameter("@.MyNTextParam". SqlDbType.NText)).Value
= MyTextArea.Text;

//Open connection and execite cmd

<adrianca@.gmail.com> wrote in message
news:1124282549.563896.53910@.o13g2000cwo.googlegro ups.com...
> Hi All,
> Does anyone have any example of asp.net code for saving a
> textarea into a text/ntext column in sql table?
> thanks
> slyi
Thank you thats perfect.
i just see any examples on the web for this :o(

Textarea to sql 2000 text datatype

Hi All,
Does anyone have any example of asp.net code for saving a
textarea into a text/ntext column in sql table?
thanks
slyiShouldn't be any different to storing any other type of data.
Are you having problems testing this normally?
Just create a Stored Procedure to do it, and set the parameter.
Worked for me
HTH
My Example:
*****************
Sql
******************
CREATE PROCEDURE [spname]
@.MyNTextParam NTEXT
AS
INSERT INTO MYTABLE VALUES(@.MyNTextParam)
*************
c#
*************
SqlCommand cmd = new SqlCommand([spname], [connectionstring]);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.add(new SqlParameter("@.MyNTextParam". SqlDbType.NText)).Value
= MyTextArea.Text;
//Open connection and execite cmd
<adrianca@.gmail.com> wrote in message
news:1124282549.563896.53910@.o13g2000cwo.googlegroups.com...
> Hi All,
> Does anyone have any example of asp.net code for saving a
> textarea into a text/ntext column in sql table?
> thanks
> slyi
>
Thank you thats perfect.
i just see any examples on the web for this :o(