【问题标题】:How to receive Csv file from android using c# wcf and save to server如何使用 c# wcf 从 android 接收 Csv 文件并保存到服务器
【发布时间】:2014-03-27 02:35:51
【问题描述】:

我使用的是 asp.net 2010,并且我有一个 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);

我的下一个代码是什么。请帮忙。

【问题讨论】:

    标签: c# android asp.net wcf


    【解决方案1】:

    你做得对。你已经掌握了信息流。

    现在使用 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
        }
    

    【讨论】:

    • 我将如何以编程方式进行
    • @user3463171 不确定您的意思,但现在添加了代码示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多