I'm having an issue with this following bit of code. When I upload a file I want it to overwrite the existing file is there is one, but i'm getting an error when I try to do it.
Protected Sub upBulkUpload_FileUploaded(ByVal sender As System.Object, ByVal args As CuteEditor.UploaderEventArgs) Handles upUpload.FileUploaded
Dim strPath = Server.MapPath("/files/bustours/itinerary/")
Dim filename As String = args.FileName
Dim strFilePath = strPath & filename
args.MoveTo(strFilePath)
Dim fileUpl As New IO.FileInfo(strFilePath)
If Not fileUpl Is Nothing Then
SM.ConfirmationMessage = "Your itinerary document has been uploaded"
SM.RedirectText = "Back to Bus Tours"
SM.RedirectURL = "/bus-tours/"
ASM.RedirectToConfirmationPage()
Else
SM.ConfirmationMessage = "Error uploading your itinerary document. Please go back and try again"
SM.RedirectText = "Back"
SM.RedirectURL = "/bus-tours/admin/itinerary.aspx"
ASM.RedirectToConfirmationPage()
End If
args.Delete()
End Sub
Cannot create a file when that file already exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at CuteEditor.UploaderProvider.MoveTo(Guid fileguid, String newpath)
at CuteEditor.UploaderEventArgs.MoveTo(String newpath)
at MFTInstallSet.MFTWeb.Itinerary.upBulkUpload_FileUploaded(Object sender, UploaderEventArgs args)
One suggestion is to use the
System.IO.File class methods and check if the file exists in the particular location and if file exists delete the file and then execute the move operation
Protected Sub upBulkUpload_FileUploaded(ByVal sender As System.Object, ByVal args As CuteEditor.UploaderEventArgs) Handles upUpload.FileUploaded
Dim strPath = Server.MapPath("/files/bustours/itinerary/")
Dim filename As String = args.FileName ''= MFT.WebFunctions.FileFunctions.GetAvailableFileName(args.FileName, strPath)
Dim strFilePath = strPath & filename
'Check if the file exists
If System.IO.File.Exists(strFilePath) Then
'Delete the Existing file
System.IO.File.Delete(strFilePath)
End If
'Execute the Move to operation
args.MoveTo(strFilePath)
Dim fileUpl As New IO.FileInfo(strFilePath)
If Not fileUpl Is Nothing Then
SM.ConfirmationMessage = "Your itinerary document has been uploaded"
SM.RedirectText = "Back to Bus Tours"
SM.RedirectURL = "/bus-tours/"
ASM.RedirectToConfirmationPage()
Else
SM.ConfirmationMessage = "Error uploading your itinerary document. Please go back and try again"
SM.RedirectText = "Back"
SM.RedirectURL = "/bus-tours/admin/itinerary.aspx"
ASM.RedirectToConfirmationPage()
End If
args.Delete()
End Sub
Member
2 Points
5 Posts
Cannot create a file when that file already exists.
Nov 21, 2013 11:27 AM|Jhunsey|LINK
I'm having an issue with this following bit of code. When I upload a file I want it to overwrite the existing file is there is one, but i'm getting an error when I try to do it.
Cannot create a file when that file already exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at CuteEditor.UploaderProvider.MoveTo(Guid fileguid, String newpath)
at CuteEditor.UploaderEventArgs.MoveTo(String newpath)
at MFTInstallSet.MFTWeb.Itinerary.upBulkUpload_FileUploaded(Object sender, UploaderEventArgs args)
All-Star
50841 Points
9895 Posts
Re: Cannot create a file when that file already exists.
Nov 21, 2013 11:42 AM|A2H|LINK
Hi,
One suggestion is to use the System.IO.File class methods and check if the file exists in the particular location and if file exists delete the file and then execute the move operation
Aje
My Blog | Dotnet Funda
Member
2 Points
5 Posts
Re: Cannot create a file when that file already exists.
Nov 21, 2013 11:52 AM|Jhunsey|LINK
Works perfectly!
Thanks for your help!