FileExists - Getting File Names

Thread is closed for posting
3 posts, 1 answers
  1. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 03 Dec 2008 Link to this post

    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.

  2. Answer
    Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 08 Dec 2008 Link to this post

    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.
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 09 Dec 2008 Link to this post

    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!
Back to Top