Date/Time stamped and numbered filenames when saving to jpeg?

mench2

New member
Joined
Oct 19, 2009
Messages
1
Programming Experience
Beginner
Right now the existing VB code I have uses GUID to generate "random" filenames on save.

For instance:

ff8514d389a041649fd8b925a32f2b51.jpg
e1c938560fc1464ab2138065fc4661d3.jpg


Instead I want a date stamp and numbered filename:

for instance:

20091015_131644_001.jpg <--(Date_Time_NumberIncrement)
20091015_131551_002.jpg

Or something along those lines...

The current code (which saves a jpeg to a random GUID filename) is below:

VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.IO

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
     Inherits System.Web.Services.WebService


    <WebMethod()> _
    Public Function SaveJPEG(ByVal strJPEG As String) As String

        'saves an uploaded photo and returns a unique name reference

        Dim BinaryContent As Byte() = Convert.FromBase64String(strJPEG)

        Try
            'generate a unique name (GUID) for the filename
            Dim strFileName As String = System.Guid.NewGuid.ToString("n")
            '
            
            Dim fStream As New FileStream("D:\photos\" + strFileName + ".jpg", FileMode.CreateNew)

            Dim bw As New BinaryWriter(fStream)

            bw.Write(BinaryContent)
            bw.Close()
            fStream.Close()

            'return the filename for use in Flash
            Return strFileName

        Catch ex As Exception

            Return ex.Message

        End Try

    End Function

End Class
 
When I've done this for a file that gets created daily I've used this code.

VB.NET:
Dim fileName as String = Now.ToShortDate.Replace("/","-")
 
Back
Top