Author: richard112 | Posted on: 4/5/2009 12:55:04 PM | Views : 413

Hi, i was just making an upload function where users can upload pictures, and i ran into a little problem.

I found out that each time someone uploades a file with the same flename, it replaces the other persons picture, so i cam up with this code that if it conflicts with the current filenames, for example "image" it replaces it with "image-1".

const string PictureDirectory = "~/Picture/"; string PicturePath = PictureDirectory + PictureUpload.FileName; string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(BrochureUpload.FileName); int iteration = 1; while (System.IO.File.Exists(Server.MapPath(brochurePath))) { picturePath = string.Concat(PictureDirectory, fileNameWithoutExtension, "-", iteration, ".jpg"); iteration++; }

And to simplify this, i would just like the image to be named after the UserId of the person who uploaded the ima ...

Go to the complete details ...