• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7569
  • Last Modified:

c# write text file to network path

I try to use this below:
//write to file test
                            TextWriter tw = new StreamWriter("\\servername\test.txt");
                            tw.WriteLine("test1");
                            tw.Close();

I get illegal characters in path.

Thoughts?
0
mileyja
Asked:
mileyja
  • 2
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
TRY WITH:
TextWriter tw = new StreamWriter(@"\\servername\test.txt");
0
 
Jaime OlivaresSoftware ArchitectCommented:
notice the backslash is a special character in c#, that's why the @ is used to disable it, also you can do as:
TextWriter tw = new StreamWriter("\\\\servername\\test.txt");
0
 
mileyjaAuthor Commented:
I will give this a try early next week when I am in the office and let you know.

Thanks,

Jamie
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now