Pass Filepath between webforms
-
Hi, I've created an ASP.NET web application using C#. My first page takes creates a text file that is shared on my network and is used as a log file for another program. The text file name has a datetime stamp in it (ex: File_2009_01_21_13_33.txt). On my second page, I need to open this text file instance and read it and write the last line to the webpage. I cannot figure out how to pass the text file name from the first webpage to the second web page. I need to use the exact path and derive the file name from that because there is the possibility that multiply text files can exist in the folder and be running at the same time. If anyone knows how I would greatly appreciated some help! Thank you.
-
Hi, I've created an ASP.NET web application using C#. My first page takes creates a text file that is shared on my network and is used as a log file for another program. The text file name has a datetime stamp in it (ex: File_2009_01_21_13_33.txt). On my second page, I need to open this text file instance and read it and write the last line to the webpage. I cannot figure out how to pass the text file name from the first webpage to the second web page. I need to use the exact path and derive the file name from that because there is the possibility that multiply text files can exist in the folder and be running at the same time. If anyone knows how I would greatly appreciated some help! Thank you.
So, your app is not going to be used on the internet ? You can put the path on the URL, or store it in the session.
Christian Graus Driven to the arms of OSX by Vista.
-
So, your app is not going to be used on the internet ? You can put the path on the URL, or store it in the session.
Christian Graus Driven to the arms of OSX by Vista.
-
The application is run in localhost. How do you store it in session? And will that work if more than one instance of the application is running at the same time?
This is what I have so far. Perhaps this can help you see what I am doing/intending to do: Form1.aspx.cs public void button_Click(object sender, EventArgs e) { string dt= string.Format("Text{0:yyyy-MM-dd_hh-mm-ss}.txt", DateTime.Now); StreamWriter sw; sw= File.CreateText(@"C:\Documents and Settings\user\Desktop\Request\" +dt); sw. WriteLine("This is the first line"); sw.Close(); string filepath = @"C:\Documents and Settings\user\Desktop\Request\" +dt; FileInfo file = new FileInfo(filepath); string filename= Path.GetFileName(filepath); } Form2.aspx.cs public void Timer1_Tick(object sender, EventArgs e) { FileStream file = new FileStream (filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); StreamReader sr = new StreamReader(file); string s= null; while ((s= sr.ReadLine()) != null) { if (s.IndexOf("Current Statue: ") != -1) { lblStatus.Text = s; break; } } sr.Close(); } Because the text file is a log file, I need to continuously monitor it as it is being updated. Hence, I've placed it inside an UpdateControl and set it inside the timer so that every time the timer goes off, the file is looked into. The error I'm encountering is that the "filename" is not being recognized in the second form. Thanks