this is not working

i m using this coding in windoews application.but compiler is giving e

Page 1 of 1

3 Replies - 722 Views - Last Post: 01 February 2009 - 11:23 PM Rate Topic: -----

#1 priks_24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-January 09

this is not working

Post icon  Posted 31 January 2009 - 03:01 AM

 public partial class Form2 : Form
	{
		public string MapPath(string virtualPath)
	   
		public Form2()
		{
			InitializeComponent();
		  
		}
			 private void Page_Load(object sender, EventArgs e)
	{
	 
	  string fullpath = Request.MapPath("~\\connection.txt");

	  try
	  {
		// Read the contents of the file using a StreamReader.
		using (StreamReader sr = new StreamReader(fullpath))
		while (sr.Peek() >= 0)
		{
		  Response.Write((char)sr.Read());
		}
		Message.Text = "Reading the file was successful.";

	  }
	  catch (Exception ex)
	  {
		Message.Text = "The process failed.";
	  }	
	 
  }



Is This A Good Question/Topic? 0
  • +

Replies To: this is not working

#2 hunter_8086  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 19-June 08

Re: this is not working

Posted 31 January 2009 - 03:09 AM

View Postpriks_24, on 31 Jan, 2009 - 02:01 AM, said:

WRONG CODE
								 string fullpath = Request.MapPath("~\\connection.txt");



		  Response.Write((char)sr.Read());



Use this

Request.MapPath this will return root path of Virtual Dir....
but in Winfrom u dont need Virtual Path


string AppPath = Application.StartupPath ;

string fullpath = AppPath + @"\connection.txt"


System.Consol.Write(((char)sr.Read());
u can't use Responce.Write in WinForms...

This post has been edited by hunter_8086: 31 January 2009 - 03:35 AM

Was This Post Helpful? 0
  • +
  • -

#3 priks_24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-January 09

Re: this is not working

Posted 01 February 2009 - 11:12 PM

thanks hunter_8086,
but that coding is also not working.I want to read a text file line by line and it should be displayed in a listbox. I am using following coding but i dont know where i m wrong.


 string line;
				   string AppPath = Application.StartupPath;
				   string fullpath = AppPath + @"\connection.txt";
				   using (StreamReader sr = new StreamReader(fullpath))
				 
					   while ((line = sr.ReadLine()) != null)
					   {
						   Console.WriteLine(line);
						   listBox1.Items.Add(line);
					   }



Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: this is not working

Posted 01 February 2009 - 11:23 PM

This is what we are able to see of the description in the description field:

Quote

this is not working, i m using this coding in windoews application.but compiler is giving e


Can you please provide the exact error message you're receiving (in the body of your post, not in the description field) so we know what steps need to be taken :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1