String concatination

  • Thread starter Rajika Somasiri
  • Start date
R

Rajika Somasiri

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;

}

}
 
A

Anusha Nanayakkara

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
 
A

Anusha Nanayakkara

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,638
Members
47,244
Latest member
Robertfem

Latest Threads

Top