Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Pass Filepath between webforms

Pass Filepath between webforms

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Terick
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • T Terick

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      T 1 Reply Last reply
      0
      • C Christian Graus

        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.

        T Offline
        T Offline
        Terick
        wrote on last edited by
        #3

        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?

        T 1 Reply Last reply
        0
        • T Terick

          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?

          T Offline
          T Offline
          Terick
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups