This is a migrated thread and some comments may be shown as answers.

FileExists - Getting File Names

2 Answers 80 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 04 Dec 2008, 12:18 AM
Ok, so here is my dilemma. I have read through all the posts on here that are tagged with "FileExists". My upload control allows multiple files to be uploaded. This is tied to a form with other data. When the user clicks submit I need to submit the other data to a database and then I need to iterate through all of the files and insert records for each of those with the filename of the file on the server. Soooooo...if I hook up to RadUpload.FileExists and rename the file, how am I going to go through and insert records for each file with accurate names? I have heard suggestions to build a collection of strings. My question is with what?? I could easily create a collection of all the files that had to be renamed with their new names but that is not ALL of the files that were uploaded, it is just the ones that had to be renamed. So then I could iterate through the UploadedFiles collection but the problem with that is that it is going to also return the files that had to be renamed. Get what I am saying? End game: I just want to be able to insert a record into the DB for each file that is uploaded with the correct file name.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 08 Dec 2008, 03:25 PM
Hi Joe,

You need to do the following:
  • Do not use TargetFolder or PhysicalTargetFolder properties, but save the files manually in the button click event handler.
  • Before saving the files you can check if there is a file with the same name and rename it appropriately.
With this you gain - the UploadedFiles collection of all the uploaded files. Also, you will know exactly which file is renamed and which not.

I hope this helps.
Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jfkrueger
Top achievements
Rank 1
answered on 09 Dec 2008, 05:21 PM
Hey thanks! That will definitely work. I was just hoping to be able to use the FileExists event. What I ended up doing was keeping the FileExists event and continuing to use the TargetFolder property and then in the FileExists event I save the original file name and the new file name to a collection. Then when I go to insert the record I iterate through the uploaded files and see if any of the names match any of the names in the collection created in the FileExists event. If so, I just use the new file name (in the collection) rather than the original file name and post it to the database. Maybe a little messy but it seems to work ok.

Thanks again!
Tags
Upload (Obsolete)
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
jfkrueger
Top achievements
Rank 1
Share this question
or