无法创建新目录 [英] Trouble creating new directory

查看:68
本文介绍了无法创建新目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用c#并运行位于共享

主机上的网站。有问题的代码应该创建一个新的

目录,该目录来自一个文本框。


它在我的计算机上工作正常,但我得到了以下

堆栈跟踪:


System.IO.DirectoryNotFoundException:找不到路径D的部分

:\" ;.在System.IO .__ Error.WinIOError

(Int32 errorCode,String str)

System.IO.Directory.InternalCreateDirectory(String

fullPath ,System.IO.DirectoryInfo.Create中的$ String $)
()at testapps.createdir.CreateSubDirectory(String direc)


要创建的代码是as如下:


public bool CreateSubDirectory(string direc)

{

bool returnStatus = false;

DirectoryInfo di = new DirectoryInfo(@direc);

if(di.Exists)

{

Trace.Write(" Directory exists) +

di.FullName);

this.Label1.Text ="目录存在;

}

else

{

Trace.Write(目录不存在+

di.FullName);

this.Label1.Text ="目录没有

存在" ;;

尝试

{

di.Create();

if(di.Exists)

{

Trace.Write(& ;目录存在

创建后);

this.Label1.Text + ="目录

在创建后存在;

}

}

catch(例外情况)

{

这个。 Label1.Text + ="错误尝试

创建不存在的目录" + ex.ToString();

Trace.Write(创建目录时出错

不存在+ ex);

}

}

返回returnStatus;

}


任何想法或建议,它都很棒在我当地的

机器上?


Sheldon Cohen
sh ****** @ hotmail.com

Hello,
I am using c# and running a site that is on a shared
host. The code in question is supposed to create a new
directory that is coming out of a text box.

It works fine on my computer, but I get the following
stack trace:

System.IO.DirectoryNotFoundException: Could not find a
part of the path "D:\". at System.IO.__Error.WinIOError
(Int32 errorCode, String str) at
System.IO.Directory.InternalCreateDirectory(String
fullPath, String path) at System.IO.DirectoryInfo.Create
() at testapps.createdir.CreateSubDirectory(String direc)

The code to create is as follows:

public bool CreateSubDirectory(string direc)
{
bool returnStatus = false;
DirectoryInfo di = new DirectoryInfo(@direc);
if(di.Exists)
{
Trace.Write("Directory exists " +
di.FullName);
this.Label1.Text = "Directory exists";
}
else
{
Trace.Write("Directory does not exist " +
di.FullName);
this.Label1.Text = "Directory does not
exists";
try
{
di.Create();
if(di.Exists)
{
Trace.Write("Directory exists
after creating it");
this.Label1.Text += "Directory
exists after creating it";
}
}
catch(Exception ex)
{
this.Label1.Text += "Error trying to
create directory that did not exist " + ex.ToString();
Trace.Write("Error creating directory
that does not exist " + ex);
}
}
return returnStatus;
}

Any ideas or suggestions, it works great on my local
machine?

Sheldon Cohen
sh******@hotmail.com

推荐答案



可能是错误的误称,但我认为问题的根源(没有
$ b以外的数据$ b您在主机服务器上配置的目录。想象一下,如果你可以 - 你可以

探测整个服务器并搜索所有其他网站的文件,这将是一个安全风险,至少可以说。


+++ Rick ---


-


Rick Strahl

West Wind Technologies
http://www.west- wind.com/
http://www.west- wind.com/wwHelp

--------------------------------- -

在网上掀起波澜

" Sheldon Cohen" < SH ****** @ hotmail.com>在消息中写道

新闻:2d ***************************** @ phx.gbl ...

This may be a misnomer of an error, but I think the root of your problem (no
pun intended) is that you don''t have permissions to get at data outside of
your configured directory on the Host server. Imagine if you could - you can
probe the entire server and scavage all the other site''s files which would
be a bit of a security risk to say the least.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web
"Sheldon Cohen" <sh******@hotmail.com> wrote in message
news:2d*****************************@phx.gbl...
您好,
我正在使用c#并运行共享
主机上的站点。有问题的代码应该创建一个来自文本框的新目录。

它在我的计算机上工作正常,但我得到以下
堆栈跟踪:

System.IO.DirectoryNotFoundException:找不到路径的一部分D:\。 at System.IO .__ Error.WinIOError
(Int32 errorCode,String str)位于System.IO.DirectoryInfo.Create的System.IO.Directory.InternalCreateDirectory(String
fullPath,String path)
()at testapps.createdir.CreateSubDirectory(String direc)

要创建的代码如下:

public bool CreateSubDirectory(string direc)
{
bool returnStatus = false;
DirectoryInfo di = new DirectoryInfo(@direc);
if(di.Exists)
{
Trace.Write(")目录存在+
di.FullName);
this.Label1.Text ="目录存在;
}
其他
{
跟踪.Write(目录不存在+
di.FullName);
this.Label1.Text ="目录不存在
;
尝试
{
di.Create();
if(di.Exists)
Trace.Write(目录存在后创建它);
this.Label1 .Text + ="目录
在创建之后就存在了;
}
}
catch(Exception ex)
{
this.Label1.Text + =&尝试创建不存在的目录时出错 + ex.ToString();
Trace.Write(创建目录
不存在的错误+ ex);
}
}
返回returnStatus ;


任何想法或建议,它在我当地的机器上运行良好吗?

谢尔顿科恩
sh ****** @ hotmail.com



谢谢, 那讲得通。我联系了我的主人,他们没有

一个线索该做什么。有关如何使其工作的任何建议吗?


谢谢,


Sheldon Cohen


***通过开发人员指南 http://www.developersdex.com 发送***

不要只是参加USENET ......获得奖励!
Thanks, that makes sense. I have contacted my host and they do not have
a clue what to do. Any suggestions of how I could get this working?

Thanks,

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


谢谢,这是有道理的。我联系了我的主人,他们没有

一个线索该做什么。有关如何使其工作的任何建议吗?


谢谢,


Sheldon Cohen


***通过开发人员指南 http://www.developersdex.com 发送***

不要只是参加USENET ......获得奖励!
Thanks, that makes sense. I have contacted my host and they do not have
a clue what to do. Any suggestions of how I could get this working?

Thanks,

Sheldon Cohen

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于无法创建新目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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