我怎样才能上传C#3.0中文件的完整路径? [英] How can I get uploaded file full path in C# 3.0?
问题描述
在我的ASP.NET MVC的网站,我要读一些名字和电子邮件由separeted一个txt文件;。在那之后,我要救这个txt文件到数据库中的每一行。
In my ASP.NET MVC website, I have to read a txt file with some names and emails separeted by ';'. After that, I have to save each line of this txt file to database.
周围的Googling,我发现了一些片段,但在所有这些我都用txt文件的路径。
Googling around, I've found some snippets, but in all of them I have to use the txt file path.
但是,我怎么能得到这个路径?该文件可能是在用户的机器的任何地方!
But, how can I get this path? This file could be anywhere in a user's machine!
谢谢!
推荐答案
您无法获得上传文件的完整路径。这将是一个侵犯隐私为上传该文件的用户。
You cannot get the full path of an uploaded file. This would be a privacy violation for the user that uploaded the file.
相反,你需要阅读已上载的Request.Files。例如:
Instead, you'll need to read the Request.Files that have been uploaded. For example:
HttpPostedFile file = Request.Files[0];
using (StreamReader reader = new StreamReader(file.InputStream))
{
while ((string line = reader.ReadLine()) != null)
{
string[] addresses = line.Split(';');
// Do stuff with the addresses
}
}
这篇关于我怎样才能上传C#3.0中文件的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!