String concatination

Discussion in 'ASP .Net Web Controls' started by Rajika Somasiri, Feb 9, 2004.

  1. In the following code "fname" is a variable for a file name and "name" is a
    string variable. But when I use fname it does not contain the ".txt" part.
    Therefore I cannot create the file.

    private StreamWriter StartTracking(string name)

    {

    try

    {

    if(!Directory.Exists("Info"))

    Directory.CreateDirectory("Info");

    string fname = "Info\\" + DateTime.Now.ToString("ddMMyyHHmm")+ name+ ".txt";


    infowriter = new StreamWriter(new FileStream(fname,
    FileMode.OpenOrCreate,FileAccess.Write));

    return infowriter;

    }

    catch(Exception ev)

    {

    string msg = ev.Message;

    return null;

    }

    }
     
    Rajika Somasiri, Feb 9, 2004
    #1
    1. Advertising

  2. Hi,

    "name" may be use as a keyword. You better try with strName insted of "name" variable.

    Anusha

    >In the following code "fname" is a variable for a file name and "name" is a
    > string variable. But when I use fname it does not contain the ".txt" part.
    > Therefore I cannot create the file.
    >
    > private StreamWriter StartTracking(string name)
    >
    > {
    >
    > try
    >
    > {
    >
    > if(!Directory.Exists("Info"))
    >
    > Directory.CreateDirectory("Info");
    >
    > string fname = "Info\\" + DateTime.Now.ToString("ddMMyyHHmm")+ name+ ".txt";
    >
    >
    > infowriter = new StreamWriter(new FileStream(fname,
    > FileMode.OpenOrCreate,FileAccess.Write));
    >
    > return infowriter;
    >
    > }
    >
    > catch(Exception ev)
    >
    > {
    >
    > string msg = ev.Message;
    >
    > return null;
    >
    > }
    >
    > }
    >
    >
    >
    >
    >
    >
    >


    ___
    Newsgroups brought to you courtesy of www.dotnetjohn.com
     
    Anusha Nanayakkara, Feb 23, 2004
    #2
    1. Advertising

  3. Hi
    Use "strName" insted of "name" variable and try weather it's working

    Anusha.

    >In the following code "fname" is a variable for a file name and "name" is a
    > string variable. But when I use fname it does not contain the ".txt" part.
    > Therefore I cannot create the file.
    >
    > private StreamWriter StartTracking(string name)
    >
    > {
    >
    > try
    >
    > {
    >
    > if(!Directory.Exists("Info"))
    >
    > Directory.CreateDirectory("Info");
    >
    > string fname = "Info\\" + DateTime.Now.ToString("ddMMyyHHmm")+ name+ ".txt";
    >
    >
    > infowriter = new StreamWriter(new FileStream(fname,
    > FileMode.OpenOrCreate,FileAccess.Write));
    >
    > return infowriter;
    >
    > }
    >
    > catch(Exception ev)
    >
    > {
    >
    > string msg = ev.Message;
    >
    > return null;
    >
    > }
    >
    > }
    >
    >
    >
    >
    >
    >
    >


    ___
    Newsgroups brought to you courtesy of www.dotnetjohn.com
     
    Anusha Nanayakkara, Feb 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jakob Simon-Gaarde

    Preprocessor concatination of defines

    Jakob Simon-Gaarde, Jul 1, 2004, in forum: C++
    Replies:
    4
    Views:
    453
    Jack Klein
    Jul 2, 2004
  2. JChG
    Replies:
    1
    Views:
    259
    Steven D'Aprano
    Apr 19, 2010
  3. Noah Roberts
    Replies:
    5
    Views:
    819
    James Kanze
    Jan 12, 2011
  4. Rajika Somasiri

    String concatination

    Rajika Somasiri, Feb 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    155
    Tom Kiefer
    Feb 9, 2004
  5. Crystal
    Replies:
    3
    Views:
    136
    Crystal
    Jul 9, 2003
Loading...

Share This Page