如何将文件上传到特定文件夹 [英] How to upload the file into a specific folder

查看:162
本文介绍了如何将文件上传到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件上传到根目录之外的文件夹中,该根目录将在webconfig路径中指定,该路径可以在系统的任何驱动器中.我想从Web配置读取值.

我需要对路径进行硬编码,例如:D:\somefolder\FileUploadFolder

我的webconfig文件是

I want to upload the file into a folder which is outside of the root whose path will be specified in webconfig path can be in any drive of the system. I want to read the value from web config.

I need to hardcode the path like: D:\somefolder\FileUploadFolder

my webconfig file is

<add key="FileUploadFolder" value="D:\somefolder\FileUploadFolder"/>


string folder_from_config = ConfigurationManager.AppSettings["FileUploadFolder"].ToString();


FileUpload1.SaveAs(folder_from_config + "\\" + System.IO.Path.GetFileName(FileUpload1.FileName));


出现类似


am getting error like

same error is" ''c:\somefolder\FileUploadFolder\sheet.xls'' not a valid virtual path."


的错误
任何解决方案



any solution

推荐答案

您不能将上传的文件保存到IIS内未定义的虚拟文件夹的任何文件夹中.通常,在网站文件夹层次结构之外保存/加载文件是一种不好的做法.
You can''t save an uploaded file to any folder that isn''t a virtual folder defined inside IIS. Generally, it''s bad practice to save/load files OUTSIDE of the website''s folder hierarchy.


这篇关于如何将文件上传到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆