Solved

using a new guid as a file name

Posted on 2008-10-02
6
470 Views
Last Modified: 2008-10-04
Hi,

Users can upload images onto my site.

However I want to rename them and give them a random name.

I wanted to create a guid that would be used as the filename.

Something like:
Dim file As String = newFileName.ToString & "." & file_ext

but when i create the file with that the name is:
00000000-0000-0000-0000-000000000000.JPG

any ideas?
0
Comment
Question by:scm0sml
6 Comments
 
LVL 5

Expert Comment

by:gemailj
ID: 22626112
try to use this
Guid newFileName = Guid.NewGuid(); //this create a new rondom Guid
instead of
Guid newFileName = new Guid();   //this create  a zero guid doesn't calulate it

Guid newFileName = Guid.NewGuid();

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22626148
indeed there is a ready-made method like:

Dim fn as String = System.IO.Path.GetTempFileName()
0
 

Author Comment

by:scm0sml
ID: 22626221
i cant guarentee that being unique tho can i?
 - Dim fn as String = System.IO.Path.GetTempFileName()

gemailj: is that c#? im using vb.net
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Accepted Solution

by:
tasky earned 200 total points
ID: 22626372
Gemailj's code in VB.NET is:

Dim newFileName As Guid = Guid.NewGuid()
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 150 total points
ID: 22626433
GetTempFileName creates a zero-byte file that is guaranteed to be unique and non previous existing.
0
 
LVL 5

Assisted Solution

by:gemailj
gemailj earned 150 total points
ID: 22626489
yes it is c#
this is the vb equivalent
Dim newFileName As Guid = Guid.NewGuid

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now