How to split the filename and take a number attached to it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • georgetjojo
    New Member
    • Jan 2008
    • 3

    How to split the filename and take a number attached to it

    Hi Guys,
    I got a vb.net page in which the user is uploading a .doc file and what I need to do is put an _ at the end of the file name if the file is uploaded for the first time and later on if some one edits the same file and upload ,I need to save it with a version number like filename_ 001,002 .... after the _.So can anyone tell me how to use the split function and check from the database whether the file has already been uploaded before or not.Also another problem is that I need to check from the right side of the file name since if the file name is already having a _ other than the one I append,then if the name is scanned from the left side,as in usual case is going to cause problem.Hope anyone can help me with this.
    Thanks
  • leoiser
    New Member
    • Jul 2007
    • 41

    #2
    Your Question is not clear.

    If you want to check/get last uploaded file of

    select top 1 UploadFileName from tblUploadFile where UploadFileName like 'filename_%' order by UploadedDate DESC

    The above query will give you last uploaded file

    in VB.net do a checking
    'Assuming u need to check file name start with "myFile_"
    Dim sFileName As String = "myFile_"

    If dr.HasRows() Then
    If dr.Read() Then
    sFileName = sFileName + (Convert.ToInt6 4(Convert.ToStr ing(dr("UploadF ileName")).Repl ace(sFileName, "")) + 1).ToString("00 0")
    End If
    Else
    sFileName = sFileName + "001"
    End If


    is it met your requirement?

    Originally posted by georgetjojo
    Hi Guys,
    I got a vb.net page in which the user is uploading a .doc file and what I need to do is put an _ at the end of the file name if the file is uploaded for the first time and later on if some one edits the same file and upload ,I need to save it with a version number like filename_ 001,002 .... after the _.So can anyone tell me how to use the split function and check from the database whether the file has already been uploaded before or not.Also another problem is that I need to check from the right side of the file name since if the file name is already having a _ other than the one I append,then if the name is scanned from the left side,as in usual case is going to cause problem.Hope anyone can help me with this.
    Thanks

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      You mean want just file name before "_", for ex xyz_001.xxx then u want xyz right ??

      If yes then you can split filename by "_" character and u get filename

      Or u can generate like query in ur sql statement

      Comment

      • georgetjojo
        New Member
        • Jan 2008
        • 3

        #4
        Actually what i mean was I need to get the version numbers like 001,002 etc.but if i start slitting the filename from left,then if the filename is having another _ then it wil be a problem right?for eg file_name_001.d oc.here since i got 2 _ how can i get the version number 001 as such.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by georgetjojo
          Actually what i mean was I need to get the version numbers like 001,002 etc.but if i start slitting the filename from left,then if the filename is having another _ then it wil be a problem right?for eg file_name_001.d oc.here since i got 2 _ how can i get the version number 001 as such.
          You have to make sure that the file name is in the format that you expect.
          Set a rule stating that the version number must be at the end of the file name and that it is 3 digits long.
          Then you can take the last 3 characters in the filename string (excluding the extension of course...).

          Check out the methods for the String class.

          -Frinny

          Comment

          • kunal pawar
            Contributor
            • Oct 2007
            • 297

            #6
            then take last Item of array and plz trim part of .doc

            Comment

            Working...