2014-09-30 22 views
-1

我試圖調整我的代碼以將FileInfo列表的數據保存到文件中。 這是塊代碼我用來保存一個字符串在一個文本文件:保存在服務器上的文本文件中的列表內容

public static void writeToServer(string title, string mystring, string username, string password) 
    { 
     // Get the object used to communicate with the server. 
     FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://XX.XXX.XXX.XX/local/ASPXGENERATED/"+title.Replace(" ","")+".aspx"); 
     request.Method = WebRequestMethods.Ftp.UploadFile; 
     string skeletonFilled = ""; 

     request.Credentials = new NetworkCredential (username,password); 
     request.UsePassive = true; 
     request.UseBinary = true; 
     request.KeepAlive = false; 

     // Copy the contents of the file to the request stream. 
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();  

     byte[] bytes = Encoding.GetEncoding("UTF-8").GetBytes(mystring); 

     Stream requestStream = request.GetRequestStream(); 
     requestStream.Write(bytes, 0, bytes.Length); 
     requestStream.Close(); 

    } 

這工作perfecly但我缺乏我的想法,使之與列表,而不是一個字符串工作。 理想的情況下,我想單獨所有的列表元素用「」 非常感謝您的幫助

PS:我使用.NET 3.5 v

回答

1

使其與列表工作而不是一個字符串。理想情況下,我想 單獨所有的列表元素「」

您可以通過使用String.Join連接具有分隔多個字符串:

string finalString = string.Join(",", aStringArray); // use List.ToArray to create one from a list 

「PS:我使用.NET v 3.5「已在.NET 2中工作。

+0

非常感謝。我沒有想到這個伎倆 – Slrg 2014-09-30 21:56:38

相關問題