how to read the content of the file using Fileupload

前端 未结 2 1086
深忆病人
深忆病人 2021-01-12 08:18

Is it possible to read the content of a file using Fileupload.

For example I want to save the XML file in Database , a user search the file using Fileupload and then

2条回答
  •  -上瘾入骨i
    2021-01-12 08:51

    we cannot directly read the file, instead of that we should save it in the project location. using the project file path we can read with the help of stream reader.

    var filePath = Path.Combine(Server.MapPath("~/Document"), fileName);
                    file.SaveAs(filePath);
    
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        using (StreamReader sr = new StreamReader(Path.Combine(Server.MapPath("~/Document"), fileName)))
                        {
                            while (sr.Peek() >= 0)
                            {
                                strbuild.AppendFormat(sr.ReadLine());
                            }
                        }
    
                    }
    

    for more details:http://www.infinetsoft.com/Post/How-to-read-text-file-using-fileupload-control-in-asp-net-MVC/1245

提交回复
热议问题