文件上传路径问题“不是有效的虚拟路径“。 [英] File upload path issue " is not a valid virtual path".

查看:325
本文介绍了文件上传路径问题“不是有效的虚拟路径“。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经给出了文件上传路径,而且没有将上传的文件保存在目录中



我尝试了什么:



Hi I have given file upload path and it not saving the uploaded file in the directory

What I have tried:

String targetFolder =  Server.MapPath("~D:\\New folder");
file.SaveAs(Path.Combine(targetFolder, "file.txt"));

推荐答案

Server.MapPath方法 [ ^ ]



上面有注意页面:



Server.MapPath Method[^]

There is this Caution on the above page:

Quote:

出于安全原因,AspEnableParentPaths属性有一个默认值值设置为FALSE。除非将AspEnableParentPaths设置为TRUE,否则脚本将无法访问物理目录结构。

For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE.





如果没有特定的错误信息,很难说是什么发生。猜测,我会说您正在尝试访问应用程序安全设置范围之外的路径。



Without the specific error information, it is hard to say what is happening. At a guess, I would say that you're trying to access a path outside the scope of the app's security settings.


string folderPath = Server.MapPath("~/Files/");
       
    //Check whether Directory (Folder) exists.
    if (!Directory.Exists(folderPath))
    {
        //If Directory (Folder) does not exists. Create it.
        Directory.CreateDirectory(folderPath);
    }
 
    //Save the File to the Directory (Folder).
    FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));


这篇关于文件上传路径问题“不是有效的虚拟路径“。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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