file lock on entry form

This is a discussion on "file lock on entry form" within the ASP.NET Forum section. This forum, and the thread "file lock on entry form are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 5th, 2007, 09:24
welshstew's Avatar
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,388
Blog Entries: 13
Thanks: 1
Thanked 17 Times in 15 Posts
file lock on entry form

Is anyone available to help??

I have a asp form that writes to a text file, however, if i get more than one user entering at exactly the same time i get a file lock issue. below is my code, is there anyway to stop this from happening??

Thanks in advance. stew

Code: Select all
<script runat="server">

    void Page_Load(Object semder, EventArgs e)
    {
    
          try
            {

          lblError.Visible = false;
    
                if (!Page.IsPostBack)
                {
                
                
                }
                else
                {
                    Page.Validate();
                    if (Page.IsValid)
                    {
                       // get the form values
                        string firstName = txtFirstName.Text.Trim();
                        string middleName = txtMiddleName.Text.Trim();
                        string lastName = txtLastName.Text.Trim();
                        string postcode = txtPostcode.Text.Trim();
                    string phone = txtPhone.Text.Trim();
                    //string optin = radFurtherInfo.SelectedValue;
                    string datenow = System.DateTime.Today.ToString("dd-MMM-yyyy");
    
                        // write 'em out to a text file
                        if (!WriteToTextFile(firstName, middleName, lastName, postcode, phone, datenow))
                        {
                            lblError.Visible = true;
                        }
    
                        // redirect to the microsite
                        Response.Redirect("entryform_success.html");
    
                    }
            }
    }    
    catch(Exception ex)
    {
        //just swallow the error
    }
    }
    
    
    private bool WriteToTextFile(string firstName, string middleName, string lastName, string postcode, string phone, string datenow)
    {
    
            bool success = true;
    
           StreamWriter sw = null;
        try
            {
                // Change this to the location you want to save the data
                // Be careful with permissions on this file, it shouldn't be browsable
                // E.g. string filename = "d:\\webdata\\events\\"
                string fileName = "c:\\comp_entry_07\\entry_"+ datenow +".txt";
                sw = new StreamWriter(fileName, true);
    
                sw.WriteLine(firstName.Replace(",", "") + "," + middleName.Replace(",", "") + "," + lastName.Replace(",", "")
                    + "," + postcode.Replace(",", "") + "," + phone + ","+ datenow);
    
                sw.Close();
             }
            catch(Exception ex)
            {
               lblError.Text = ex.Message;
                success = false;
            }
        finally
            {
               if (sw != null)
               sw.Close();
             }

    
    
            return success;
    }

</script>
Last Blog Entry: Web Standards Curriculum Launched (Jul 8th, 2008)
Reply With Quote

  #2 (permalink)  
Old Jun 7th, 2007, 08:22
welshstew's Avatar
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,388
Blog Entries: 13
Thanks: 1
Thanked 17 Times in 15 Posts
Re: file lock on entry form

I've been reading that I can put some sort of lock function into the code, anyone got any ideas?

Or any way of speeding up the data dump into the text file?

oh yeah, the reason for using a text file is that I am unable to place a db onto the server, security and all that.
__________________
WelshStew
Lead Administrator

tierney rides tboard - uk site | xtreme wales - extreme clothing
If you think I've helped, click the "Thanks"
webforumz - facebook | LinkedIn
Last Blog Entry: Web Standards Curriculum Launched (Jul 8th, 2008)
Reply With Quote
Reply

Tags
aspnet, file lock, forms

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
File Upload Contact Form jjpeacha PHP Forum 2 May 8th, 2008 17:20
PHP form and csv file Gabriele PHP Forum 1 Mar 22nd, 2008 15:43
Simultaneous entry ASP form error welshstew Classic ASP 1 May 21st, 2007 16:01
How do i "lock" a form field? Accurax Web Page Design 7 Mar 15th, 2007 01:01
Working with Form 'file field' data in ASP. daryl Classic ASP 3 Jun 24th, 2006 20:22


All times are GMT. The time now is 06:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43