Solved

using a new guid as a file name

Posted on 2008-10-02
6
465 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
Comment Utility
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
Comment Utility
indeed there is a ready-made method like:

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

Author Comment

by:scm0sml
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Accepted Solution

by:
tasky earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
yes it is c#
this is the vb equivalent
Dim newFileName As Guid = Guid.NewGuid

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

16 Experts available now in Live!

Get 1:1 Help Now