Solved

c# write text file to network path

Posted on 2008-06-11
3
7,159 Views
Last Modified: 2013-12-17
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
Comment
Question by:mileyja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21761064
TRY WITH:
TextWriter tw = new StreamWriter(@"\\servername\test.txt");
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 21761077
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
 

Author Comment

by:mileyja
ID: 21842108
I will give this a try early next week when I am in the office and let you know.

Thanks,

Jamie
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question