nexpay

TXT to DB

شروع موضوع توسط amin1us ‏9 دسامبر 2005 در انجمن asp , ASP.NET

  1. amin1us

    amin1us کاربر تازه وارد

    تاریخ عضویت:
    ‏2 ژوئن 2004
    نوشته ها:
    199
    تشکر شده:
    0
    سلام مي خواستم ببينم كسي مي دونه چطوري داده ها رو از رو يه فايل TXT بخونيم خط به خط بخونه تو DATA BASE بريزه همين؟!؟!:cool:
     
  2. artin

    artin کاربر تازه وارد

    تاریخ عضویت:
    ‏19 می 2004
    نوشته ها:
    2,112
    تشکر شده:
    2
    خوب روی هر خط چند تا فیلد هست ؟ یعنی هر خط یک رکورد میشه ؟ یا باید تو فیلدهای مختلف تقسیم بشه ؟
     
  3. amin1us

    amin1us کاربر تازه وارد

    تاریخ عضویت:
    ‏2 ژوئن 2004
    نوشته ها:
    199
    تشکر شده:
    0
    هر خط يك ركورد
    باشه خوبه
     
  4. amin1us

    amin1us کاربر تازه وارد

    تاریخ عضویت:
    ‏2 ژوئن 2004
    نوشته ها:
    199
    تشکر شده:
    0
    كسي نيست يه كمكي بكنه؟
     
  5. mazoolagh

    mazoolagh کاربر فعال شبکه و صفحات استاتیک کاربر فعال

    تاریخ عضویت:
    ‏10 آپریل 2004
    نوشته ها:
    2,940
    تشکر شده:
    7
    Microsoft® Scripting Library - FileSystemObject
    Working with Files




    --------------------------------------------------------------------------------

    There are two major categories of file manipulation:

    Creating, adding, or removing data, and reading files
    Moving, copying, and deleting files
    Creating Files
    There are three ways to create an empty text file (sometimes referred to as a "text stream").
    The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using this method in VBScript:

    کد:
    Dim fso, f1
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
    To use this method in JScript, use this code:
    کد:
    var fso, f1;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f1 = fso.CreateTextFile("c:\\testfile.txt", true);
    View this sample code to see how the CreateTextFile method is used in FileSystemObject.
    The second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set. In VBScript, the code looks like this example:
    کد:
    Dim fso, ts
    Const ForWriting = 2
    Set fso = CreateObject("Scripting. FileSystemObject")
    Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)
    To create a text file using this method in JScript, use this code:
    کد:
    var fso, ts;
    var ForWriting= 2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true);
    A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set. For this method, use the following code in VBScript:
    کد:
    Dim fso, f1, ts
    Const ForWriting = 2
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CreateTextFile ("c:\test1.txt")
    Set f1 = fso.GetFile("c:\test1.txt")
    Set ts = f1.OpenAsTextStream(ForWriting, True)
    In JScript, use the code in the following example:
    کد:
    var fso, f1, ts;
    var ForWriting = 2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.CreateTextFile ("c:\\test1.txt");
    f1 = fso.GetFile("c:\\test1.txt");
    ts = f1.OpenAsTextStream(ForWriting, true);
    Adding Data to the File
    Once the text file is created, add data to the file using the following three steps:

    Open the text file.
    Write the data.
    Close the file.
    To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object.
    To write data to the open text file, use the Write, WriteLine, or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table.

    Task Method
    Write data to an open text file without a trailing newline character. Write
    Write data to an open text file with a trailing newline character. WriteLine
    Write one or more blank lines to an open text file. WriteBlankLines


    View this sample code to see how the Write, WriteLine, and WriteBlankLines methods are used in FileSystemObject.

    To close an open file, use the Close method of the TextStream object.

    View this sample code to see how the Close method is used in FileSystemObject.


    --------------------------------------------------------------------------------

    Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage return/line feed). Be aware that the end of some strings may already have such nonprinting characters.

    --------------------------------------------------------------------------------



    The following VBScript example demonstrates how to open a file, use all three write methods to add data to the file, and then close the file:

    کد:
    Sub CreateFile()
      Dim fso, tf
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set tf = fso.CreateTextFile("c:\testfile.txt", True)
      ' Write a line with a newline character.
      tf.WriteLine("Testing 1, 2, 3.") 
      ' Write three newline characters to the file.      
      tf.WriteBlankLines(3) 
      ' Write a line.
      tf.Write ("This is a test.") 
      tf.Close
    End Sub
    This example demonstrates how to use the three methods in JScript:
    کد:
    function CreateFile()
    {
      var fso, tf;
      fso = new ActiveXObject("Scripting.FileSystemObject");
      tf = fso.CreateTextFile("c:\\testfile.txt", true);
      // Write a line with a newline character.
      tf.WriteLine("Testing 1, 2, 3.") ;
      // Write three newline characters to the file.      
      tf.WriteBlankLines(3) ;
      // Write a line.
      tf.Write ("This is a test.");
      tf.Close();
    }
    Reading Files
    To read data from a text file, use the Read, ReadLine, or ReadAll method of the TextStream object. The following table describes which method to use for various tasks.
    Task Method
    Read a specified number of characters from a file. Read
    Read an entire line (up to, but not including, the newline character). ReadLine
    Read the entire contents of a text file. ReadAll


    View this sample code to see how the ReadAll and ReadLine methods are used in FileSystemObject.

    If you use the Read or ReadLine method and want to skip to a particular portion of data, use the Skip or SkipLine method. The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string functions (such as Left, Right, and Mid), concatenated, and so forth.

    The following VBScript example demonstrates how to open a file, write to it, and then read from it:

    کد:
    Sub ReadFiles
      Dim fso, f1, ts, s
      Const ForReading = 1
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
      ' Write a line.
      Response.Write "Writing file <br>"
      f1.WriteLine "Hello World"
      f1.WriteBlankLines(1)
      f1.Close
      ' Read the contents of the file.
      Response.Write "Reading file <br>"
      Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
      s = ts.ReadLine
      Response.Write "File contents = '" & s & "'"
      ts.Close
    End Sub
    This code demonstrates the same thing in JScript:
    کد:
    function ReadFiles()
    {
      var fso, f1, ts, s;
      var ForReading = 1;
      fso = new ActiveXObject("Scripting.FileSystemObject");
      f1 = fso.CreateTextFile("c:\\testfile.txt", true);
      // Write a line.
      Response.Write("Writing file <br>");
      f1.WriteLine("Hello World");
      f1.WriteBlankLines(1);
      f1.Close();
      // Read the contents of the file.
      Response.Write("Reading file <br>");
      ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
      s = ts.ReadLine();
      Response.Write("File contents = '" + s + "'");
      ts.Close();
    }
    Moving, Copying, and Deleting Files
    The FSO object model has two methods each for moving, copying, and deleting files, as described in the following table.
    Task Method
    Move a file File.Move or FileSystemObject.MoveFile
    Copy a file File.Copy or FileSystemObject.CopyFile
    Delete a file File.Delete or FileSystemObject.DeleteFile


    View this sample code to see two ways to delete a file in FileSystemObject.

    The following VBScript example creates a text file in the root directory of drive C, writes some information to it, moves it to a directory called \tmp, makes a copy of it in a directory called \temp, then deletes the copies from both directories.

    To run the following example, create directories named \tmp and \temp in the root directory of drive C:

    کد:
    Sub ManipFiles
      Dim fso, f1, f2, s
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
      Response.Write "Writing file <br>"
      ' Write a line.
      f1.Write ("This is a test.")
      ' Close the file to writing.
      f1.Close
      Response.Write "Moving file to c:\tmp <br>"
      ' Get a handle to the file in root of C:\.
      Set f2 = fso.GetFile("c:\testfile.txt")
      ' Move the file to \tmp directory.
      f2.Move ("c:\tmp\testfile.txt")
      Response.Write "Copying file to c:\temp <br>"
      ' Copy the file to \temp.
      f2.Copy ("c:\temp\testfile.txt")
      Response.Write "Deleting files <br>"
      ' Get handles to files' current location.
      Set f2 = fso.GetFile("c:\tmp\testfile.txt")
      Set f3 = fso.GetFile("c:\temp\testfile.txt")
      ' Delete the files.
      f2.Delete
      f3.Delete
      Response.Write "All done!"
    End Sub
    This code shows the same thing in JScript:
    کد:
    function ManipFiles()
    {
      var fso, f1, f2, s;
      fso = new ActiveXObject("Scripting.FileSystemObject");
      f1 = fso.CreateTextFile("c:\\testfile.txt", true);
      Response.Write("Writing file <br>");
      // Write a line.
      f1.Write("This is a test.");
      // Close the file to writing.
      f1.Close();
      Response.Write("Moving file to c:\\tmp <br>");
      // Get a handle to the file in root of C:\.
      f2 = fso.GetFile("c:\\testfile.txt");
      // Move the file to \tmp directory.
      f2.Move ("c:\\tmp\\testfile.txt");
      Response.Write("Copying file to c:\\temp <br>");
      // Copy the file to \temp.
      f2.Copy ("c:\\temp\\testfile.txt");
      Response.Write("Deleting files <br>");
      // Get handles to files' current location.
      f2 = fso.GetFile("c:\\tmp\\testfile.txt");
      f3 = fso.GetFile("c:\\temp\\testfile.txt");
      // Delete the files.
      f2.Delete();
      f3.Delete();
      Response.Write("All done!");
    }
     
  6. amirlol

    amirlol کاربر تازه وارد

    تاریخ عضویت:
    ‏9 می 2005
    نوشته ها:
    47
    تشکر شده:
    0
    مرسی
    معمولآ اگه منبعی که برداشتین رو ذکر کنید بهتره !! و نیاز ها رو می شه شاید پیدا کرد از همون جا
     
  7. mazoolagh

    mazoolagh کاربر فعال شبکه و صفحات استاتیک کاربر فعال

    تاریخ عضویت:
    ‏10 آپریل 2004
    نوشته ها:
    2,940
    تشکر شده:
    7
    منبعش همون اول گفته شده - دقت کن
     
  8. amirlol

    amirlol کاربر تازه وارد

    تاریخ عضویت:
    ‏9 می 2005
    نوشته ها:
    47
    تشکر شده:
    0
    ببخشید !
    ولی اگه می شه منبع با لینک باشه زیبا تره
    بازم ببخشید
    اصلآ غلط کردم
     
  9. mazoolagh

    mazoolagh کاربر فعال شبکه و صفحات استاتیک کاربر فعال

    تاریخ عضویت:
    ‏10 آپریل 2004
    نوشته ها:
    2,940
    تشکر شده:
    7
    اگر OFFICE روی کامپیوترت نصب باشه توی دایرکتوریهای فرعیش (1033) 2 تا فایل chm هست : vbscript5 - jscript5
    که راهنمای ویبی اسکریپت و جاوااسکریپت هست و توی هر دوش هم filesystemobject توضیح داده شده. دونستن وجود این فایلها برای هر asp کاری واجبه!

    بالطبع توی MSDN هم اگر جستجو کنی میاره! من هم از MSDN کپی کردم و بهمین خاطر لینک نگذاشتم!

    ضمنا اگر windows scripting host روی سیستمت نصب کنی یک فایل script56.chm همراهش هست که 2 تا فایل بالا رو هم داخل خودش داره. ولی بهتره مستنداتش رو جداگانه دانلود کنی که حدود 2.5 مگ هست و از این که گفتم خیلی کاملتره!
     
zarpopخرید بک لینک عسل طبیعی و گرده گل ایرانیfootbal