Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Temporary File Names

Reply
Thread Tools

Temporary File Names

 
 
Bob Morris
Guest
Posts: n/a
 
      11-28-2003
I need to be able to create unique new filenames in a directory set by me,
with an extension that I set. The two commands I need are:-

Path.SetTempFilePath(string path);

and

Path.GetTempFile(string extension);

Unfortunately MS haven't provided them. Any ideas?

Bob


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      11-28-2003

"Bob Morris" <(E-Mail Removed)> wrote in message
news:%23%(E-Mail Removed)...
> I need to be able to create unique new filenames in a directory set by me,
> with an extension that I set. The two commands I need are:-
>
> Path.SetTempFilePath(string path);
>
> and
>
> Path.GetTempFile(string extension);
>
> Unfortunately MS haven't provided them. Any ideas?
>
> Bob
>
>


You could always write your own:
1) create a filename, either random or something like "fileNNN.ext" where
nnn is a number
2) check if that file already exists, if it does, repeat step 1 (increase
the number)
3) return the name that you finally ended up with

Hans Kesting


 
Reply With Quote
 
 
 
 
Richard K Bethell
Guest
Posts: n/a
 
      11-28-2003
"Bob Morris" <(E-Mail Removed)> wrote in message
news:%23%(E-Mail Removed)...
> I need to be able to create unique new filenames in a directory set by me,
> with an extension that I set. The two commands I need are:-
>
> Path.SetTempFilePath(string path);
>
> and
>
> Path.GetTempFile(string extension);


Create a Guid, and append the file extension to it. Near guaranteed
uniqueness, and easy to do. Works like a charm for me!

public string MakeUniqueName(string Ext)
{
string mvarFileName
Guid guid = Guid.NewGuid();
mvarFileName = guid.ToString().Replace("-", "");
mvarFileName += "." + Ext;
return mvarFileName;
}


 
Reply With Quote
 
Bob Morris
Guest
Posts: n/a
 
      11-29-2003
Thanks very much, I will try both the approaches suggested.

Bob

"Richard K Bethell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bob Morris" <(E-Mail Removed)> wrote in message
> news:%23%(E-Mail Removed)...
> > I need to be able to create unique new filenames in a directory set by

me,
> > with an extension that I set. The two commands I need are:-
> >
> > Path.SetTempFilePath(string path);
> >
> > and
> >
> > Path.GetTempFile(string extension);

>
> Create a Guid, and append the file extension to it. Near guaranteed
> uniqueness, and easy to do. Works like a charm for me!
>
> public string MakeUniqueName(string Ext)
> {
> string mvarFileName
> Guid guid = Guid.NewGuid();
> mvarFileName = guid.ToString().Replace("-", "");
> mvarFileName += "." + Ext;
> return mvarFileName;
> }
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
anonymous array of strings // ("taking address of temporary"- how long is temporary valid?) anon.asdf@gmail.com C++ 7 02-12-2008 10:58 AM
Removing file names with '.' in their names from list? Sfdesigner Sfdesigner Ruby 5 08-13-2007 02:38 AM
Directory and files names in temporary asp.net directory =?Utf-8?B?QmFzIEhlbmRyaWtz?= ASP .Net 5 01-31-2005 01:56 PM
logical puzzle: how to generate reasonable archive file names fromfile and directory names fBechmann Python 0 06-10-2004 07:13 AM



Advertisments