I have been told that the best place to store user pictures is inside folders and that you should have no more than 10,000 pictures per folder. I already know how to use code to check how many pictures there are in a folder but how can I create a new folder
using system.IO ? or some other method. I do not want to be constantly checking to see if I should create a new folder and since I already know how many pictures each folder has I want to simply add a new folder when 10,000 pictures are already stored in
a folder.
if (file != null && getpicture.photo != null) { // this deletes a picture System.IO.File.Delete(Server.MapPath("~/uploads/profilepic/menso/" + getpicture.photo)); } if (picture.count == 10000) { // How can I create a new folder here to store new pictures }
You can use the Directory.CreateDirectory method:
var path = Server.MapPath("~/uploads/"); Directory.CreateDirectory(Path.Combine(path, "New Folder"));
http://msdn.microsoft.com/en-us/library/54a0at6s(v=vs.110).aspx
Thank you very much, that solved it.