where to ask about opening file to write in asccii ? forms c#

david mills 21 Reputation points

//fs->WriteByte(DataBufferb[i]); // fs->CanWrite(ToString(g)); //fs->WriteLine("david"); //fs->WriteLine(DataBufferb[i]); //System::IO::FileStream^ fs = (System::IO::FileStream^)saveFileDialog1->OpenFile(); //System::IO::FileStream^ fs1 = (System::IO::FileStream^)SaveFile("d:\test.txt"); String ^ david = "d"; // fs->Write(david , 0, 6 ); fs->WriteByte(ToChar(david); please take pity LOL VS 2019 Forms c# ! so I would like to open a file(or create file) to write the word David inside file.. struggling here anyone got a link I might follow please

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,776 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,503 questions
{count} votes

Accepted answer
  1. Alberto Poblacion 1,556 Reputation points

    The easiest way to write the word David inside a file is to simply use File.WriteAllText. This will create the file if it does not exist and overwrite it if it exists.

    System.IO.File.WriteAllText("C:\folder\myfile.txt", "David");

    But note that this is C# (as per the title of your question) and not C++ (as per the sample code that you posted).

    Link to documentation.

4 additional answers

Sort by: Most helpful
  1. david mills 21 Reputation points

    fs->WriteByte(('D')); // so this line does write the character D to the file so I can see it

    fs->WriteByte(Convert::ToInt32(result1, 16)); // here result = a string of "7" but I can not get 7 in readable format into file :(

    0 comments No comments

  2. Castorix31 82,491 Reputation points

    If it is in C++/CLI, don't set the Tag dotnet-csharp, but c++ instead ( + eventually windows-forms)

    To write to a file, see MSDN documentation samples, like :

    Write a Text File

    0 comments No comments

  3. david mills 21 Reputation points

    I had found this code online :)
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
    String^ fileName = "dcmtextfile.txt";
    System::IO::StreamWriter^ sw = gcnew System::IO::StreamWriter(fileName);
    sw->WriteLine("A text file is born!");
    sw->Write("You can use WriteLine");
    sw->WriteLine("...or just Write");
    sw->WriteLine("and do {0} output too.", "formatted");
    sw->WriteLine("You can also send non-text objects:");
    Console::WriteLine("a new file ('{0}') has been written", fileName);

    //return 0;


  4. david mills 21 Reputation points

    Random question :)
    the data rate is 25000 baud.. 24 bytes per packet about 10msecs per packet then a 6 msec gap then an answer of 24 bytes...
    so is there anyway of setting a flag to say no data has arrived so I can resync the incoming data packets :) Thank you

    0 comments No comments