6

When I use

System.IO.File.WriteAllBytes("\\server\\tmp\\" + FileName, fileData);

It always seems to add "C:" to the beginning so it tries to save to c:\server\temp...

Is there a way around this?

1
  • 3
    Try a string-literal (prepending the @): WriteAllBytes(@"\\server\tmp\" + FileName, fileData); Commented Apr 26, 2013 at 2:52

3 Answers 3

11

I believe this is because the double backslash isn't escaped.

Try this instead:

System.IO.File.WriteAllBytes(@"\\server\tmp\" + FileName, fileData);
Sign up to request clarification or add additional context in comments.

Comments

5

Your current path evaluates to \server\tmp\... which will default to c:\server\tmp\....

To make a UNC path, you'll need an extra escaped directory-separator:

System.IO.File.WriteAllBytes("\\\\server\\tmp\\" + FileName, fileData);

or you can use a string-literal instead:

System.IO.File.WriteAllBytes(@"\\server\tmp\" + FileName, fileData);

Comments

1

How about his:

System.IO.File.WriteAllBytes(Path.Combine(@"\\server\tmp", FileName), fileData);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.