create a text file on the different server in C#

Hi,
I have some trouble to create a text file on a different server in C#.
I run a web applicatin on server A. When the user clicks a button, the application should create a text file on server B. We set up the path on server B like this:
\\ServerB\files

I use the following code to create the text file. But I got the error below:
Could not find a part of the path 'c:\ServerB\files\test.txt'.

Here is the code:
string strFileName= "\\ServerB\\files\\test.txt'";  
try
            {
                bResult = System.IO.File.Exists(strFileName);

                if (bResult)
                {
                    System.IO.File.Delete(strFileName);
                }

                System.IO.FileStream fs= System.IO.File.Create(strFileName);

                byte[] b = new System.Text.UTF8Encoding(true).GetBytes(System.DateTime.Now.ToString());
                fs.Write(b,0,b.Length);
                fs.Close();
                       }
            catch (Exception ex)
            {
                string strErr = ex.Message.ToString();
             }

I really appreciate if anyone can help me with this problem.
 

Jinghui LiAsked:
Who is Participating?
 
_Katka_Connect With a Mentor Commented:
Hi, I think you should use

string strFileName= "\\\\ServerB\\files\\test.txt'";  

OR

string strFileName= @"\\ServerB\files\test.txt'";  

regards,
Kate
0
 
Jinghui LiAuthor Commented:
It is work!
Thank you so much!

0
 
_Katka_Commented:
You're welcome :))

regards,
Kate
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.

All Courses

From novice to tech pro — start learning today.