locked
Problem with Filename RRS feed

  • Question

  • Hi,

    I'm facing an interesting problem with creating (.txt) files taking the filename from the front-end (Winform).

    When the user enters the file name containing only alphabets (Eg: DataFile) , it works fine. But if the user enters the file name having a number (Eg: DataFile1), file does'n get created.

    Following is the code am running:

    string filename = string.Format("{0}\\{1}.txt", folderBrowserDialog1.SelectedPath, textBox3.Text);

    FileStream fp = new FileStream(filename, FileMode.Append);
    StreamWriter writer = new StreamWriter(fp);
    writer.WriteLine(msg);
    writer.Close();
    fp.Close();

    Please help me on this.

    Thanks,

    Vishruth

    Tuesday, May 25, 2010 6:27 AM

Answers

All replies

  • Welcome to the MSDN Forums.

    May I ask what is the exception message?

    Thank you.


    WHAT'S NEW IN THE .NET FRAMEWORK 4:
    Article: Comparison of parallel and sequential computing in .NET Framework
    Tuesday, May 25, 2010 6:46 AM
  • Hi Yasser,

    Thanks for your reply.

    It is not giving any exception Message. It just doesn't create the file if the filename contains any number.

    -- Vishruth

     

    Tuesday, May 25, 2010 7:01 AM
  • Your code works fine here!

    Could you paste following code result for me, please?

          string filename = string.Format("{0}\\{1}.txt", folderBrowserDialog1.SelectedPath, textBox3.Text);
          Clipboard.SetText(filename);//paste result for me please
          using (FileStream fp = new FileStream(filename, FileMode.Append))
          {
            using (StreamWriter writer = new StreamWriter(fp))
            {
              writer.WriteLine(msg);
            }
          }
          Process.Start("explorer", Path.GetFullPath(filename));//should open your file folder!
    
    Thank you.
    WHAT'S NEW IN THE .NET FRAMEWORK 4:
    Article: Comparison of parallel and sequential computing in .NET Framework
    Tuesday, May 25, 2010 7:11 AM
  • i am using above code like this-

    string filename = string.Format("{0}\\{1}.txt", "C:\\Documents and Settings\\jayant\\Desktop", "DataFile1");
                String msg = "file creation is suceed";
                FileStream fp = new FileStream(filename, FileMode.Append);
                StreamWriter writer = new StreamWriter(fp);
                writer.WriteLine(msg);
                writer.Close();
                fp.Close();

     

    and it working properly at my end..and create a DataFile1.txt on desktop.

    you should check the string value in folderBrowserDialog1.SelectedPath and textbox3.text ..

    please debug your code and check the value in folderbrowserdialog.selectedpath and textbox3.text

     

    regards

    jayant

    Tuesday, May 25, 2010 7:14 AM
  • Hi Yasser / Jayanth,

    Thanks a lot for your help.

    Its now working fine for me as well. I figured out that the number in filename is not the problem, and the problem is concerned with the server from which am taking the data.

    Sorry for asking a wrong question. ~!!

    @Yasser, do you still want me to run it and paste the result, if yes plz let me know.

    Thanks Guys, Cya :)

    -- Vishruth

    Tuesday, May 25, 2010 7:57 AM
  • @Yasser, do you still want me to run it and paste the result, if yes plz let me know.

    Thanks Guys, Cya :)

    -- Vishruth


    No, Thank you.

    I just wanted to verify the file path that if it's correct in your condition.

    Thanks.


    WHAT'S NEW IN THE .NET FRAMEWORK 4:
    Article: Comparison of parallel and sequential computing in .NET Framework
    Tuesday, May 25, 2010 8:08 AM