Singel file upload renaming

Thread is closed for posting
2 posts, 0 answers
  1. Kjell
    Kjell avatar
    223 posts
    Member since:
    May 2011

    Posted 17 May 2012 Link to this post

    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")
        End If
    End Sub
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 May 2012 Link to this post

    Hi Kjell,

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

    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.

Back to Top