2012-03-16 17 views
0

私はFTP経由でPDFファイルをアップロードするために、次のコードを持っています。どのように私はそれを読まずにファイルをアップロードできますか?つまり、ファイルを選択して名前を変更してアップロードするだけです。アップロードPDFファイルは

答えて

2

WebClientクラスを使用し、UploadFileメソッドを使用します。 msdn

String uriString = Console.ReadLine(); 

// Create a new WebClient instance. 
WebClient myWebClient = new WebClient(); 
myWebClient.Credentials=new NetworkCredential(username, password); 
Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI"); 
string fileName = Console.ReadLine(); 
Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString); 

// Upload the file to the URI. 
// The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method. 
byte[] responseArray = myWebClient.UploadFile(uriString,fileName); 
+0

から は、あまりにもExcelファイルをアップロードするためのこの作品ですか。? – Praditha

+0

はい - 両方ともバイナリファイルです。 – weismat

関連する問題