radupload , FileExists , filename

Thread is closed for posting
4 posts, 0 answers
  1. Pedro
    Pedro avatar
    2 posts
    Member since:
    Jul 2011

    Posted 14 Oct 2011 Link to this post

    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
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 19 Oct 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pedro
    Pedro avatar
    2 posts
    Member since:
    Jul 2011

    Posted 19 Oct 2011 Link to this post

    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 ??
     
  5. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 24 Oct 2011 Link to this post

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