Solved

using a new guid as a file name

Posted on 2008-10-02
6
475 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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