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

Getting Final Name(s) Of Uploaded Files

1 Answer 240 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mick
Top achievements
Rank 1
Mick asked on 19 Jul 2008, 07:00 PM

Hello, I have asked this question before, but didnt get the response I desired, maybe this was due to me being unclear on my intentions, so I shall try again.
I am using the RadUpload control to allow the uploading of image files to my server. After the files a uploaded, they are minipulated server side, height, width etc are adjusted and a watermark is added, so it is very important that I have the correct filename after upload.
When the upload control detects that a file already exists, it fires the following function:

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);  
    }         
This works well, the uploaded file is renanmed by appending an extra "1" to the filename, until a unique name is generated.
However my problem is, if I try the followning in my upload button click event:
 protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (UploadedFile f in RadUpload1.UploadedFiles)  
        {  
            if (!Object.Equals(f, null))  
            {  
                LooongMethodWhichUpdatesTheProgressContext(f);  
            }  
        }  
        foreach (UploadedFile f in RadUpload1.UploadedFiles)  
        {  
            Response.Write(f.GetName() + "<br>");  
        }  
    }  
 
I only get the original filenames, if the filename has been changed by the fileexists funtion above, the correct name is not shown in the uploaded files collection. I need a way to be able to access the filenames, as they are saved on the server. Yes I can save the filename of the modified file within the fileexists method to a string list, however the original file name still exists within the uploaded files collection.

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 22 Jul 2008, 08:17 AM
Hello Mick,

The UploadedFiles collection contains all valid uploaded files. The UploadedFile class has a FileName property which contains the name of the file on the client. Additionally, the GetName() method returns that name as well.
You cannot modify the file name property in the collection.

Therefore, you need to keep the actual file names in another place, e.g. in a string array - as you already supposed.

I hope this helps.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Upload (Obsolete)
Asked by
Mick
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or