こんにちは、このようにスレッド内のフォルダーにアクセスしようとしています
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
、完全に機能します。