Solved

using a new guid as a file name

Posted on 2008-10-02
6
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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