error on file uploading if file with the same name exists in upload folder

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
darkdragon
User
Posts: 151

error on file uploading if file with the same name exists in upload folder

Post by darkdragon »

Hello,

We just finished converting a project from ANM2019 and ANM2021 and pushed to production an app where we attach files on some records.
The upload pages don't have nothing special (except some code in Row_inserting/Row_Updating where we update some fields like: CreatedBy, CreatedOn, ModifiedBy, ModifiedOn).
Also, we have only a single upload folder set-up in General Options -> File Upload.

After converting the project, the app come up with some errors if try to upload a file whose name is identical to other file (s) already in the upload folder:

IOException: The process cannot access the file because it is being used by another process.
System.IO.FileSystem.MoveFile(string sourceFullPath, string destFullPath, bool overwrite)
System.IO.File.Move(string sourceFileName, string destFileName, bool overwrite)
System.IO.File.Move(string sourceFileName, string destFileName)
AspNetMaker2021.Models.EvOLT.MoveFile(string oldFile, string newFile) in aspnetfn.cs
-
        /// </summary>
        /// <param name="oldFile">Old file</param>
        /// <param name="newFile">New file</param>
        public static void MoveFile(string oldFile, string newFile)
        {
            Collect(); // DN
            FileMove(oldFile, newFile);
        }
        /// <summary>
        /// Copy file
        /// </summary>
        /// <param name="srcFile">Source file</param>
AspNetMaker2021.Models.EvOLT+ScoringAttachmentsAddBase.AddRow(Dictionary<string, object> rsold) in ScoringAttachmentsAdd.cs
-
                                    }
                                    var folders = new[] { olsa_vc_filename.PhysicalUploadPath, tempPath };
                                    string file1 = UniqueFileName(olsa_vc_filename.PhysicalUploadPath, file); // Get new file name (without index)
                                    if (file1 != file) {
                                        while (FileExists(tempPath + file1) || FileExists(olsa_vc_filename.PhysicalUploadPath + file1)) // Make sure no file name clash
                                            file1 = UniqueFileName(folders, file1, true); // Use indexed name
                                        MoveFile(tempPath + file, tempPath + file1); // Rename temp file
                                        newFiles[i] = file1; // Update new file name
                                    }
                                }
                            }
                        }
                        olsa_vc_filename.Upload.DbValue = String.Join(Convert.ToString(Config.MultipleUploadSeparator), oldFiles);

We applied some code in order to change the name of the uploaded file, but the error still persists.
Any thoughts?


darkdragon
User
Posts: 151

Post by darkdragon »

Quite odd, editing a record with an attachment, I'm able to upload a file with the same name with one existing in the uploads folder.
The file gets renames by appending (n) before its extension.


darkdragon
User
Posts: 151

Post by darkdragon »

if Multiple is checked then the issue is gone for the Add page.
Therefore there is something odd somewhere.

I reproduced the issue son 3 different system, two win10 and one w2k2016.


MichaelG
User
Posts: 1113

Post by MichaelG »

Cannot simulate with the latest version (ASP.NET Maker 2022). Please upgrade to ASP.NET Maker 2022 and see if the issue is resolved.

Alternatively, remove or comment all your server event codes to make sure that the problem is not related to the codes.


darkdragon
User
Posts: 151

Post by darkdragon »

Unfortunately we just finished the conversion to ANM2021 and we had a lot of breaking changes.

We’ll stick around with what I found so far, until we ready for the next shot.

Thanks.


Post Reply