2014-03-27 42 views
0

我使用的是asp.net 2010,我有一個wcf web服務。 我想從android接收csv文件並將接收文件保存到我的服務器中的文件夾。如何使用c#wcf從android接收Csv文件並保存到服務器

android部分使用字節發送.Csv文件。

有沒有人有一個想法如何接收.Csv文件?

我有這個代碼爲Android應用程序調用的方法「POST」。

[WebInvoke(UriTemplate = "UploadFile/upload?filename={filename}", 
     Method = "POST", ResponseFormat = WebMessageFormat.Json)] 
     wsResponse UploadFile(string filename, System.IO.Stream fileContent); 

,什麼將是我的下一個代碼..請幫助。

回答

0

你做得對。你有這個流。

現在使用CSV解析庫來解析CSV。例如http://www.filehelpers.com/ 並執行您需要執行的任何邏輯。

樣品(你需要引用filehelpers庫) -

 [DelimitedRecord(",")] 
    public class YourTypeForCSV 
    { 
     public string Field1; 
     public int Field2; 
    } 


    void UploadFile(string filename, System.IO.Stream fileContent) 
    { 
     FileHelperEngine<YourTypeForCSV> engine = new FileHelperEngine<YourTypeForCSV>(); 

     YourTypeForCSV[] records = engine.ReadStream(new StreamReader(fileContent)); 

     // .. do whatever you need 
    } 
+0

我將如何做到這一點編程 – user3463171

+0

@ user3463171不知道你是什麼意思,但現在增加了一個代碼示例。 – Maxim

相關問題