Hi,
Is there any way to add a time stamp to the file that is being uploaded?
I have noticed that the files get replaced directly if they exist on the Uploads folder.
So, I think the best way to over come this situation would be to add a time stamp for the file being uploaded.
Regards,
Mohammed Hafeezuddin
Hi Mohammed,
yes, definitely. this is not something that is done automatically, but you can easily achieve it using server-side events in your MVC controller code (or in Global.asax). For example you can have the following code which will cancel storing the file with its original filename, and will save it in a custom location that you specify, including a new custom filename.
The upload control always saves files in a unique temporary file name first, before renaming them to the original filename sent from the client. Using this event you can control what happens with the temporary file name and where it gets stored and under what final filename.
(the temp file always gets deleted, for sure, after the UploadFinishing has fired).
[ActionName("multiple-upload")] public ActionResult MultipleUpload() { UploadProgressManager.Instance.AddFinishingUploadEventHandler("serverID1", new EventHandler<UploadFinishingEventArgs>(handler)); return View("MultipleUpload"); } protected void handler(object sender, UploadFinishingEventArgs args) { string filePath = String.Format("{0}{1}", args.FolderPath, args.TemporaryFileName); if (System.IO.File.Exists(filePath)) { try { System.IO.File.Copy(filePath, "C:\\something.pdf"); } catch (Exception ex) { } } args.Cancel = true; }
Hope it helps. Thanks,
Angel