Server.MapPath-在ASP.net中找不到路径的一部分 [英] Server.MapPath - Could not find a part of the path in ASP.net

查看:130
本文介绍了Server.MapPath-在ASP.net中找不到路径的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Server.MapPath将文件上传到服务器上

I am uploading a file to my server using Server.MapPath

运行代码时出现以下错误

When I run my code I get the following error


找不到路径
'C:\inetpub\wwwroot\wss\VirtualDirectories\80\SitePages\uploads\ ABI
Employee List.xlsx'。

Could not find a part of the path 'C:\inetpub\wwwroot\wss\VirtualDirectories\80\SitePages\uploads\ABI Employee List.xlsx'.

是的,我的服务器上没有该目录。我只有一个目录。

So Yes, I dont have that directory on my server. I only have a directory up to here.


'C:\inetpub\wwwroot\wss\VirtualDirectories\80\ b

'C:\inetpub\wwwroot\wss\VirtualDirectories\80\

所以,我去创建那些目录。

So, I go and create Those directories.

很奇怪问题是,如果我在上述目录中创建了一个名为 SitePages的文件夹,那么我的网站甚至都不想启动?删除它,它将再次起作用。 (下面的错误图片)

The weird thing is, is that if I create a folder with the name "SitePages" in the above directory, my site doesn't even want to start up? Delete it and it works again. (Image of error below)

我需要创建该目录才能将文件上传到我的服务器,但是我不能,因为一切都中断了。我该如何解决?

I need to create that directory to upload the file to my server, but I can't, since everything breaks. How will i fix this?

推荐答案

在根目录下创建目录,例如。 文件夹名称 ,然后尝试以下

create a directory in root eg. 'Foldername' and try the following

  DirectoryInfo dir = new DirectoryInfo(HttpContext.Server.MapPath("~/Foldername/"));
            if (!dir.Exists)
            {
                dir.Create();
            }
            // this makes sure that directory has been created
            // do other stuff

这篇关于Server.MapPath-在ASP.net中找不到路径的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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