2014-09-30 7 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 작동하지만 내가 그것을 목록이 아닌 문자열로 작동하도록 아이디어의 부족 해요 : 이 내가 텍스트 파일에 문자열을 저장하는 데 사용되는 블록 코드입니다. 내가 사용하고 .NET (V)가 3.5

답변

1

는이 목록에서 작동합니다 이상적으로 , 나는 ","당신의 도움에 대한 덕분에 많은

는 PS 모든 목록 요소를 분리해서 싶습니다 문자열이 아닙니다. 이상적으로, 난에와 별도의 모든 목록 요소를 싶습니다 ","

당신은 String.Join를 사용하여 분리 여러 문자열을 연결할 수 있습니다

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

"PS : 내가 사용을 .NET v 3.5 " .NET에서 이미 작동합니다.

+0

고마워요. 나는이 트릭에 대해 생각하지 않았다. – Slrg

관련 문제