Getting Uploaded Filename(s)

Thread is closed for posting
2 posts, 0 answers
  1. Mick
    Mick avatar
    27 posts
    Member since:
    Mar 2008

    Posted 10 Jun 2008 Link to this post

    Hi All,

    When using the radupload control, if the file exists I modify the filename as such:

    protected

    void RadUpload1_FileExists(object sender, UploadedFileEventArgs e) {

    int counter = 1;

    UploadedFile file = e.UploadedFile;

    string targetFolder = Server.MapPath(RadUpload1.TargetFolder);

    string targetFileName = Path.Combine(targetFolder,

    file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());

    while (System.IO.File.Exists(targetFileName))

    {

    counter ++;

    targetFileName =

    Path.Combine(targetFolder,

    file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());

    }

    file.SaveAs(targetFileName);

    }



    My question is, that .GetName() still returns the original filename and not the modified name, so how can I access the (collection of) original name(s)?

    Do I manually have to manage the save event myself? If so are there any examples of doing this?

    Kind Regards
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 13 Jun 2008 Link to this post

    Hi Mick,

    I'm afraid I could not understand your question properly. The GetName() method of the UploadedFile class returns exactly the original name of the file being uploaded. As the code is being executed in the body of the FileExists event handler, that means that there is already a file with the specified name in the target folder.

    If you need to have the new names, you can create a string collection, where you can store the modified file names.

    Let me know if I am missing something.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top