You're passing in an app-relative path. The
Directory
class doesn't know anything about ASP.NET paths. You need to map the app-relative path to a physical path first:
string virtualPath = string.Format("~/Images_LL/Timeline/userid{0}", Convert.ToInt32(Session["userid"]);
string physicalPath = Server.MapPath(virtualPath);
DirectoryInfo di = Directory.CreateDirectory(physicalPath);
Also, don't use
throw ex;
to re-throw an exception. If you do, you'll destroy the stack-trace. Use
throw;
instead.
And don't catch exceptions that you're not going to handle. Catching an exception and immediately re-throwing it has no benefit. Just remove the entire
catch (Exception ex) { ... }
block.