Date/Time Stamped and Numbered filenames when saving to jpeg?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 1
Reputation: mench2 is an unknown quantity at this point 
Solved Threads: 0
mench2 mench2 is offline Offline
Newbie Poster

Date/Time Stamped and Numbered filenames when saving to jpeg?

 
0
  #1
Oct 19th, 2009
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:

  1. Imports System.Web
  2. Imports System.Web.Services
  3. Imports System.Web.Services.Protocols
  4. Imports System.IO
  5.  
  6. ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  7. ' <System.Web.Script.Services.ScriptService()> _
  8. <WebService(Namespace:="http://tempuri.org/")> _
  9. <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  10. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
  11. Public Class Service
  12. Inherits System.Web.Services.WebService
  13.  
  14.  
  15. <WebMethod()> _
  16. Public Function SaveJPEG(ByVal strJPEG As String) As String
  17.  
  18. 'saves an uploaded photo and returns a unique name reference
  19.  
  20. Dim BinaryContent As Byte() = Convert.FromBase64String(strJPEG)
  21.  
  22. Try
  23. 'generate a unique name (GUID) for the filename
  24. Dim strFileName As String = System.Guid.NewGuid.ToString("n")
  25. '
  26.  
  27. Dim fStream As New FileStream("D:\photos\" + strFileName + ".jpg", FileMode.CreateNew)
  28.  
  29. Dim bw As New BinaryWriter(fStream)
  30.  
  31. bw.Write(BinaryContent)
  32. bw.Close()
  33. fStream.Close()
  34.  
  35. 'return the filename for use in Flash
  36. Return strFileName
  37.  
  38. Catch ex As Exception
  39.  
  40. Return ex.Message
  41.  
  42. End Try
  43.  
  44. End Function
  45.  
  46. End Class
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC