AVARICESOFT
asked on
Reading and writing the file in asp.net
hello,
my scanrio is that:
for reading via fileupload:
i have fileupload button in my webpage when user hit the button the file upload from the server and then i read the content of the given file and place the content in the textbox and also write the server path in the session varible full server path,
for writing via savdialog:
i show the download button to the user when user hit the button i have a text in my textbox, when user click the content of the textbox is save via 3 format txt, psd, doc constraint the user when save dialog box is show.
i show the gui below and remember all the contents are dynamic not static so must care for code
Note:
1- Don't give me reference URL (strickly prohabited)
2- send me the working code which which meets up my case
3- Working Code must..
case2258.jpg
my scanrio is that:
for reading via fileupload:
i have fileupload button in my webpage when user hit the button the file upload from the server and then i read the content of the given file and place the content in the textbox and also write the server path in the session varible full server path,
for writing via savdialog:
i show the download button to the user when user hit the button i have a text in my textbox, when user click the content of the textbox is save via 3 format txt, psd, doc constraint the user when save dialog box is show.
i show the gui below and remember all the contents are dynamic not static so must care for code
Note:
1- Don't give me reference URL (strickly prohabited)
2- send me the working code which which meets up my case
3- Working Code must..
case2258.jpg
use streamreader and streamwriter object in c#
///For reading:
string list ="";
StreamReader reader = new StreamReader("file.txt");
line = reader.ReadToEnd();
reader.Close();
///For Writing:
StreamWriter wrt = new StreamWriter("file.txt");
wrt.Write("your text to right"):
wrt.Close();
///For Downloading;
// 1.
// Get path of byte file.
string path = Server.MapPath("~/Adobe2.png");
// 2.
// Get byte array of file.
byte[] byteArray = File.ReadAllBytes(path);
// 3A.
// Write byte array with BinaryWrite.
Response.BinaryWrite(byteArray);
// 3B.
// Write with OutputStream.Write [commented out]
// Response.OutputStream.Write(byteArray, 0, byteArray.Length);
// 4.
// Set content type.
Response.ContentType = "image/png";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.