我的程序有上传图片的功能,上传功能在本地调试没有错.
但是传到服务器上就报"未找到路径e:的一部分"的错误.
代码我是重用的,一部分可以正常上传,但是一部分就报这种错误.在网上查过资料,大部分都是关于权限问题的解释.(但是如果是权限问题的话,为什么我有一部分程序可以正常上传呢?)不知道在服务器上我应该设哪一种权限?
但是传到服务器上就报"未找到路径e:的一部分"的错误.
代码我是重用的,一部分可以正常上传,但是一部分就报这种错误.在网上查过资料,大部分都是关于权限问题的解释.(但是如果是权限问题的话,为什么我有一部分程序可以正常上传呢?)不知道在服务器上我应该设哪一种权限?
if((topPhoto.PostedFile.ContentLength > 0) && (topPhoto.PostedFile.ContentType == "image/pjpeg" || topPhoto.PostedFile.ContentType == "image/gif" || topPhoto.PostedFile.ContentType == "image/bmp"))
{
string _v = topPhoto.Value.Trim();
string _directoryPath = Server.MapPath("SubjectImages/" + name.Text.Trim() + "/");
System.Random _rd = new Random();
string _fileName = "top-" + DateTime.Now.ToString("yyyyMMddHHmmss") + _rd.Next(100000).ToString();
string _ex = _v.Substring(_v.IndexOf(".",0)+1,3);
if(Directory.Exists(_directoryPath) == false)
{
try
{
Directory.CreateDirectory(_directoryPath);
topPhoto.PostedFile.SaveAs(_directoryPath + _fileName + "." + _ex);
t1 = "SubjectImages/" + name.Text.Trim() + "/" + _fileName + "." + _ex;
}
catch
{
throw;
}
}
else
{
topPhoto.PostedFile.SaveAs(_directoryPath + _fileName + "." + _ex);
t1 = "SubjectImages/" + name.Text.Trim() + "/" + _fileName + "." + _ex;
}
}
-------------------------
应该是缺少路径,比如你的目录只有e:\abc\ ,而你的上传代码却指向 e:\abc\def\ ,这样因为没有def目录,通常就报这样的错误,LZ仔细检查一下上传路径先。
------------------------------------
按照您的提示我试了一下,正如你所说,事先将目录建好再上传文件的话,一切正常.
但是我现在要动态创建目录.利用Directory类创建.如果是这样的话,这种错误应该怎么排除呢?
最终还是权限的问题?