告诉你asp.net MVC 如何获取文件路径相对路径

发布时间:2024-03-27 点击:105
主要是为了上传文件路径,而html5在其他好多的浏览器中不能直接返回路径给你。
主要思路:把文件上传到服务器的指定文件夹中,然后拼接字符串拼接出它在服务器的路径,然后保存到数据库。
html代码:
<formaction=/data/uploadfilemethod=post enctype=multipart/form-data id=formfile>
<inputtype=file name=file />
<inputclass=importdatatype=submit value=导入/>
}
</form>
控制器代码:
public actionresult uploadfile()
{
string path =server.mappath(~/content/img/);//设定上传的文件路径
if (!directory.exists(path))
{
directory.createdirectory(path);
}
//判断是否已经选择上传文件
httppostedfilebase file =request.files[file];
string filenname =file.filename;
string filepath = path filenname;
file.saveas(filepath);//上传路径
//然后你就可以用filepath新增到数据库里面了。
return content();
}

SEO常用到标签汇总及讲解
公司域名邮箱注册流程和公司域名邮箱的好处
电商网站优化 怎么才能让网站更好地盈利
解析域名到中国建渣清运网
在哪里可以申请免费的域名?域名的作用是什么?
浅谈网站改版如何才是好的改版?
租linux云服务器吗
关于手机网站开发费用的明细