Reputation: 82
i have built an admin panel where admin uploads images to server(they are actualy images of products)
at first i named them acording to my ProductObject.ID so when admin uploaded image to product with a id of 45 the image would be named 45_1 the second picture 45_2
but now i want to change it because when adding images to existing product it works great but creating new product with images couses problems because there is no product id while saving the images
so what i wanna do is every time admin saves image to server, make the program to give unique number to it and keep these numbers(23423.jpg) in a List and save this List to a file
what i wanna know is how can i save that list to a file and after that read it so i know the image name is unique
Upvotes: 1
Views: 730
Reputation: 29654
As an alternative to using a Guid as stated by @nmat, you could also use Path.GetTempFileName
. (http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx)
This would give you a unique filename while you figure out what you want to do with the file.
Upvotes: 0
Reputation: 7591
To ensure that you have unique IDs you should use Guids. You can add the product identifier before that if you prefer:
Guid g = Guid.NewGuid();
String filename = productId + "_" + g.ToString();
A Guid is always unique so you don't need to worry about that. You need however to save the image identifier somewhere for later access (in a database or in a file, as you prefer)
Upvotes: 1