if (HttpContext.Current != null)
{
localpath = HttpContext.Current.Server.MapPath(directorypath);
}
else
{
directorypath = directorypath.Replace("/", "\");
localpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directorypath);
}