我使用Server.MapPath将文件上传到服务器
当我运行我的代码时,我会得到以下错误
找不到路径'C:\inetpub\wwwroot\wss\VirtualDirectories\80\SitePages\uploads\ABI Employee List.xlsx‘的一部分。
所以是的,我的服务器上没有那个目录。到目前为止我只有一个目录。
'C:\inetpub\wwwroot\wss\VirtualDirectories\80\
所以,我去创建那些目录。
奇怪的是,如果我在上面的目录中创建一个名为"SitePages“的文件夹,我的站点甚至不想启动?删除它,它就会再次工作。(下面是错误图像)
我需要创建这个目录来将文件上传到我的服务器,但是我做不到,因为所有东西都坏了。我该怎么解决这个问题?

发布于 2013-05-03 11:31:49
在根目录下创建一个目录。'Foldername'并尝试以下内容
DirectoryInfo dir = new DirectoryInfo(HttpContext.Server.MapPath("~/Foldername/"));
if (!dir.Exists)
{
dir.Create();
}
// this makes sure that directory has been created
// do other stuff发布于 2013-05-03 11:42:20
您可以在虚拟目录中手动创建一个文件夹名,并尝试以下代码:
public static string GetPath()
{
string Path = string.Empty;
try
{
Path = HttpContext.Current.Server.MapPath("~/FolderName/");
}
catch (Exception _e)
{
}
return Path;
}发布于 2013-05-03 12:12:42
尝试在运行时创建所需的文件夹。可以通过以下方式创建目录
if(!Directory.Exists("YourDirectory"))
{
Directory.CreateDirectory("YourDirectory")
}https://stackoverflow.com/questions/16357839
复制相似问题