Reputation: 37
i want to save Chart image to my computer and Image name is ChartName+Date+Time Ex PieChart13jan20141127.JPEG
is any format for time and date can do that , because my format in my Code is return nothing my code is :
If My.Computer.FileSystem.DirectoryExists("C:\charts") Then
Dim todaysdate As String = String.Format("{ddmmyyyy}", System.DateTime.Today)
Chart1.SaveImage("C:\charts\PieChart" & todaysdate & ".Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
MessageBox.Show("Done")
Else
MsgBox("Please create Charts Folder @ C:\")
End If
Upvotes: 0
Views: 2617
Reputation: 460380
You can use DateTime.Now.ToString("ddMMMyyyyHHmm")
(uppercase MMM
for month)
Dim file As String = "PieChart" + DateTime.Now.ToString("ddMMMyyyyHHmm")
Dim fileName As String = String.Format("{0}{1}", file, ".Jpeg")
Dim fullName As String = System.IO.Path.Combine("C:\charts", fileName)
I prefer Path.Combine
to build the path since it increases readability and is less error-prone.
Upvotes: 1
Reputation: 27342
To get the current date and time in a specific format use DateTime.Now.ToString(aFormat)
where aFormat
is a string of the format of date and time you require:
See here for all the formats available: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Upvotes: 0