Click here to Skip to main content
15,903,817 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all
I have a code to file upload is below
VB
ofdDocToUpload.Filter = "All files (*.*)|*.*"
           If ofdDocToUpload.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
               Exit Sub
           End If
           txtReqDocPath.Text = ofdDocToUpload.FileName

which give the output like that
C:\Documents and Settings\superkings\Desktop\work on_25Jan2011.txt

but now requirement is that datetime should be add before the file name like below
F:\EOSPROJECTS\MCSAdmin\ContactMasterFiles\2011310155114_TestWord35.docx
how can I achieve that please help
Posted

First, get the current date, then prefix it in a formatted manner:
VB
Dim now As DateTime = DateTime.Now
txtReqDocPath.Text = now.ToString("yyyyMMddhhmmss_") + ofdDocToUpload.FileName

You may have to change the format string, I can't see how you get "2011310155114" from yesterdays date!
There is a full list of the format specifiers here: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Mar-11 10:31am    
I guess the format was the problem. My 5.
--SA
Espen Harlinn 15-Mar-11 12:50pm    
Nice and simple - my 5
When you upload a file, you only transfer its contents, not any attributes, so the time of creation and last modification of the file is lost. You can only use the local server's time at the moment when the file is uploaded. This is not a problem: on download, call the property System.DateTime.Now or System.DateTime.UtcNow, convert it to string using the culture you want and concatenate with the file name where you use it. You need to use format with characters allowed for file name, no '/' characters (replace them with '-' or something like that).

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900