大家好,我想像这样访问我的线程中的文件夹
protected string GetFolderName(int OrgID)
{
string FolderName = string.Empty;
string[] strDirectories = Directory.GetDirectories(HttpContext.Current.Server.MapPath("~/Uploads/"));
if (strDirectories.Length > 0)
{
for (int count = 0; count < strDirectories.Length; count++)
{
string name = strDirectories[count].Substring(strDirectories[count].LastIndexOf("\\") + 1);
if (name.Contains("_"))
{
string companyId = name.Substring(name.LastIndexOf("_") + 1);
if (Convert.ToInt32(companyId) == OrgID)
{
FolderName = name;
break;
}
}
}
}
return FolderName;
}
此方法是通过线程池调用的,它在此行上给了我“对象引用未设置为对象的实例”的错误
string[] strDirectories = Directory.GetDirectories(HttpContext.Current.Server.MapPath("~/Uploads/"));
请帮帮我
解决方案
我用它HttpRuntime.AppDomainAppPath
代替HttpContext.Current.Server.MapPath
并且效果很好。