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

Singel file upload renaming

1 Answer 124 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Iron
Kjell asked on 17 May 2012, 11:56 AM
Instead of renaming the file, this code create a new file with the new name (resultat.aspx), but leaving the old file.
How rename the uploaded file, not create a new one?
I only uploaded a singel file
Public Sub uploadFile(ByVal sender As Object, ByVal e As System.EventArgs)
 
    If RadUpload1.UploadedFiles.Count > 0 Then
 
        Dim file As UploadedFile = UploadedFile.FromHttpPostedFile(Request.Files(0))
        Dim targetFolder As String = Server.MapPath(RadUpload1.TargetFolder)
        Dim targetFileName As String = System.IO.Path.Combine(targetFolder, "resultat.xlsx")
 
        file.SaveAs(targetFileName)
 
    End If
 
End Sub

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 May 2012, 01:19 PM
Hi Kjell,

Here is the sample code which I tried to rename an uploaded file.

C#:
foreach (UploadedFile file in RadUpload1.UploadedFiles)
      {
           string fullPath = Server.MapPath("~/Uploads");
           string fileName = "newName";
           file.SaveAs(Path.Combine(fullPath, fileName + file.GetExtension()));
      }

Hope this helps.

Thanks,
Princy.
Tags
Upload (Obsolete)
Asked by
Kjell
Top achievements
Rank 1
Iron
Answers by
Princy
Top achievements
Rank 2
Share this question
or