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. General Programming
  3. C#
  4. Using StreamWriter...... Help Guys [modified]

Using StreamWriter...... Help Guys [modified]

Scheduled Pinned Locked Moved C#
5 Posts 4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:

    modified on Tuesday, April 7, 2009 2:38 PM

    B A 2 Replies Last reply
    0
    • L Lost User

      I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:

      modified on Tuesday, April 7, 2009 2:38 PM

      B Offline
      B Offline
      behzadcp
      wrote on last edited by
      #2

      i think you must select file encoding utf8 or utf32

      L 1 Reply Last reply
      0
      • B behzadcp

        i think you must select file encoding utf8 or utf32

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What? How will I select file encoding utf8 or utf32? help :((

        1 Reply Last reply
        0
        • L Lost User

          I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:

          modified on Tuesday, April 7, 2009 2:38 PM

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          If I have understood you correctly, you want to generate a VBscript or Jscript file from within your C# app. All you have to do is write the contenst of the fiel exactly like you would in notepad or whatever. You would probably want to change the file extension (to .vbs for the VBScript file), but thats all, there is nothing special about it.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          A 1 Reply Last reply
          0
          • A Ashfield

            If I have understood you correctly, you want to generate a VBscript or Jscript file from within your C# app. All you have to do is write the contenst of the fiel exactly like you would in notepad or whatever. You would probably want to change the file extension (to .vbs for the VBScript file), but thats all, there is nothing special about it.

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            A Offline
            A Offline
            al3xutzu00
            wrote on last edited by
            #5

            Try using this code:

                private void btnSave\_Click(object sender, EventArgs e)
                {
                    FileDialog salvareFisier = new SaveFileDialog();
                    salvareFisier.Filter = "Text files (\*.txt)|\*.txt";
                    if (salvareFisier.ShowDialog() == DialogResult.OK)
                    {
                        FileStream fisier = new FileStream(salvareFisier.FileName, FileMode.Create, FileAccess.Write);
                           
                            addText(fisier,"your \_text \_ here ");
                            addText(fisier, "\\r\\n");
            
                        fisier.Close();
                    }
                    else
                        MessageBox.Show("Data has not been saved");
                }
            
                public static void addText(FileStream f, string valoare)
                {
            
                    byte\[\] info = UTF8Encoding.Default.GetBytes(valoare);
                    f.Write(info, 0, info.Length);
                }
            

            Regards, Alex

            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