?
Solved

create a text file on the different server in C#

Posted on 2009-04-21
3
Medium Priority
?
201 Views
Last Modified: 2012-05-06
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.
 

0
Comment
Question by:Jinghui Li
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
_Katka_ earned 2000 total points
ID: 24199524
Hi, I think you should use

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

OR

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

regards,
Kate
0
 

Author Comment

by:Jinghui Li
ID: 24199596
It is work!
Thank you so much!

0
 
LVL 10

Expert Comment

by:_Katka_
ID: 24199622
You're welcome :))

regards,
Kate
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

750 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