Actively Edit File

Last post 12-23-2009 2:44 PM by mrmercury. 2 replies.

Sort Posts:

  • Actively Edit File

    20 hours, 35 minutes ago
    • Member
      point Member
    • mattloto
    • Member since 15 hours, 39 minutes ago
    • Posts 1

    Hi.  I am experimenting with AJAX with ASP for the first time and I have a question.  I want to have a textbox that when a user will type in something a txt file on the server will change to the textbox's text instantaneous, like real-time editing.  I have the textbox and a timer.  The timer goes every 10 ms and opens a text reader and changes the text to textbox1.text, yet the contents are not being updated in the textbox.  Any help?  Oh and I did turn EnablePageMethods to true and I know that the timer is executing.

    Here is the code:

        Dim send As IO.StreamWriter
        Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            send.Write(TextBox1.Text)
        End Sub
    
        Sub WebForm1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            send = FileIO.FileSystem.OpenTextFileWriter("doc.txt", False)
        End Sub



  • Re: Actively Edit File

    10 hours, 46 minutes ago
    • All-Star
      36,552 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,909

    Hey,

    I think you are writing the data to the stream but not saving it?

    The examples on this page wrap the stream usage in a using() block which will call the dispose methods when its finished writing - i don't know if that is what flushes the file to disk?


    Also you might be having a file path issue, would be better to use something like

    send = FileIO.FileSystem.OpenTextFileWriter(Server.MapPath("~/App_Data/doc.txt", False)


  • Re: Actively Edit File

    4 hours, 3 minutes ago
    • Contributor
      5,096 point Contributor
    • mrmercury
    • Member since 04-04-2006, 6:26 PM
    • Mexico City, Mexico
    • Posts 741

    It’s not really a good idea to call the server every 10 ms for every user in your application, this would consume all of your server’s resources, it looks that you are using UpdatePanels, they are way slower than WebServices which makes thinks even worse, if you need to edit the file actively then you could use the JavaScript  onkeyup event and WebServices, this will give a better performance by using less resources.

    If this post helped you please remember to set it as Answer so it can help others.
Page 1 of 1 (3 items)