Can the server use a file from a client without uploading it to the server? ASP.NET

柔情痞子 提交于 2019-12-05 18:24:22

I don't see how you would get a file from the client to the server without uploading it, but you don't need to store it to a folder. If you use the

    <asp:FileUpload ID="fuMyUpload" runat="server" /> 

control. you can get the data in a stream and store it in memory.

    if (!fuMyUpload.HasFile)
    {
         lblWarning.Text = "No file Selected";
         return;
    }

    var csvData = Encoding.UTF8.GetString(fuCircuitCsv.FileBytes);

    using (var reader = new StringReader(csvData))
    {
          var headers = reader.ReadLine().Split(',');
          while ((line = reader.ReadLine()) != null)
          {
                 var fields = line.Split(',');
          }
    }

If you have a background job running on the server which monitors the folder for any CSV file, then it needs to be uploaded to the server. If that is not the case, then you should be able to process the file in C# only and perform database update.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!