locked
Renaming the upload to essentially an ID RRS feed

  • Question

  • User1470670532 posted

    I basically want my upload control to upload the images and then rename them to 1,2,3,4,5,6,7 and so on as they are being passed through my stored procedure into a database to be used elsewhere but I'm having trouble renaming on upload. The upload code is very basic and as below.

      Private Sub cmdUpload_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles BtnUpload.Click
            Dim sFileDir As String = "~/Evidence/"
            'check that the file has been selected and it's a valid file
            If (Not FileUpload1.PostedFile Is Nothing) _
               And (FileUpload1.PostedFile.ContentLength > 0) Then
                'determine file name
                Dim sFileName As String = _
                   System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
                Try
                    If FileUpload1.PostedFile.ContentLength <= lMaxFileSize Then
                        Dim filepath As String
                        'save file on disk
    
                        filepath = Server.MapPath("~/Evidence/" & FileUpload1.FileName)
                        FileUpload1.SaveAs(filepath)
                        RunSP(constring, "easp_Uploadfile", "", False, 120, Membership.GetUser.ProviderUserKey, DateTime, sFileName)
                        lblStatus.Visible = True
                        lblStatus.Text = "File: " + sFileDir + sFileName + _
                           " Uploaded Successfully"
                    Else
                        lblStatus.Visible = True
                        lblStatus.Text = "File Size if Over the Limit of " + _
                           lMaxFileSize
                    End If
                Catch exc As Exception
                    lblStatus.Visible = True
                    lblStatus.Text = "An Error Occured. Please Try Again!"
                    DeleteFile(sFileDir + sFileName)
                End Try
            Else
                lblStatus.Visible = True
                lblStatus.Text = "Nothing to upload. Please Try Again!"
            End If
        End Sub

    Thanks for any feedback.

    Tuesday, July 10, 2012 4:38 AM

Answers

  • User-661350001 posted

    make RunSp as a function and return the Sequence or ID from the SP and then

    dim id = RunSP(constring, "easp_Uploadfile", "", False, 120, Membership.GetUser.Provi.........

    filepath = Server.MapPath("~/Evidence/" & id)
                       
    FileUpload1.SaveAs(filepath)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 10, 2012 5:32 AM

All replies

  • User-661350001 posted

    make RunSp as a function and return the Sequence or ID from the SP and then

    dim id = RunSP(constring, "easp_Uploadfile", "", False, 120, Membership.GetUser.Provi.........

    filepath = Server.MapPath("~/Evidence/" & id)
                       
    FileUpload1.SaveAs(filepath)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 10, 2012 5:32 AM
  • User1470670532 posted

    Ah I'd guessed as much thank you very much, not that great at sql so I was hoping for an easier route through VB but thanks again, time to spent a few hours trying to make it work. Laughing

    Tuesday, July 10, 2012 5:35 AM