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

radupload , FileExists , filename

3 Answers 220 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Pedro
Top achievements
Rank 1
Pedro asked on 14 Oct 2011, 05:13 PM
hi

Im facing here some dilema , I am using the radupload control to push some files to the server , they will be dropped in some folder i defined in the control with  TargetFolder , i have subscribed the FileExists event handler to check if some file with the same name exists on target everything is fine till here, the thing is that when a file is renamed to not overwrite another in the destination folder i cannot update its new name on the radupload control let me explain
void RadUpload1_FileExists(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e)
       {
           int counter = 1;
           UploadedFile file = e.UploadedFile;
           string targetFolder = Server.MapPath(this.RadUpload1.TargetFolder);
           string targetFileName = System.IO.Path.Combine(targetFolder,
               file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());
           while (System.IO.File.Exists(targetFileName))
           {
               counter++;
               targetFileName = System.IO.Path.Combine(targetFolder,
                   file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());
           }
           file.SaveAs(targetFileName);
           file.FileName = System.IO.Path.GetFileName(targetFileName); // <---- this line here
            }

i need this because later i loop through uploaded files , and do some more processing on them ... i can think on several ways to go arround this but isnt conceptually wrong not beeing able to update the filename ???

thanks for your time , and i hope im not missing something obvious

3 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 19 Oct 2011, 12:35 PM
Hi Pedro,

As I'm seeing you are using the implementation of the help article regarding this event. The problem is that after you save the file you want to assign value to the FileName property which has no setter method, it's a read only property.

Kind regards,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Pedro
Top achievements
Rank 1
answered on 19 Oct 2011, 02:34 PM
Thats what I said , I know it is read only prop... thats the point!, I want to know , regarding this situation why it was impemented  readonly ?? 
I did not test it yet but im goingo to check the filestream prop too , is it updated accordingly ?? , does it point to the internal temp files cache of the webserver , agnostic to the new file location ???  or it is pointing to the already existing file on the destination dir
dont get me wrong , but assuming fileStream follows filename implementation , its serious trouble here !!!

on the ther hand , like i asked before , I may be using this wrong ... so let me reformulate the question :

in the need of changing the name and location of an uploaded file through radupload in RadUpload1_FileExists, what should i do to update the radpuload object  accordingly , since its state is iconsistent with whats in the filesystem ???? should i just discard it ??? 

Can you understand my point in here ??
 
0
Dimitar Terziev
Telerik team
answered on 24 Oct 2011, 08:01 AM
Hello Pedro,

I understand the point that you have here. The FileName is a property of a file which when uploaded is stored as a temporary file which you could not modify since it's managed by the ASP.NET framework itself. If you don't save this file on the file system the file will be deleted by the server automatically.  So when you save it you could use whatever name that you want. This is why there is a SaveAs method that you should use to save it physically on the server.

Best wishes,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Upload (Obsolete)
Asked by
Pedro
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Pedro
Top achievements
Rank 1
Share this question
or