Temporary File Names

Discussion in 'ASP .Net' started by Bob Morris, Nov 28, 2003.

  1. Bob Morris

    Bob Morris Guest

    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
     
    Bob Morris, Nov 28, 2003
    #1
    1. Advertising

  2. Bob Morris

    Hans Kesting Guest

    "Bob Morris" <> wrote in message
    news:%23%...
    > 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
     
    Hans Kesting, Nov 28, 2003
    #2
    1. Advertising

  3. "Bob Morris" <> wrote in message
    news:%23%...
    > 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;
    }
     
    Richard K Bethell, Nov 28, 2003
    #3
  4. Bob Morris

    Bob Morris Guest

    Thanks very much, I will try both the approaches suggested.

    Bob

    "Richard K Bethell" <> wrote in message
    news:...
    > "Bob Morris" <> wrote in message
    > news:%23%...
    > > 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;
    > }
    >
    >
     
    Bob Morris, Nov 29, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy McCarthy
    Replies:
    3
    Views:
    753
    Anthony J Bybell
    Sep 24, 2004
  2. =?Utf-8?B?QmFzIEhlbmRyaWtz?=

    Directory and files names in temporary asp.net directory

    =?Utf-8?B?QmFzIEhlbmRyaWtz?=, Jan 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    905
    Juan T. Llibre
    Jan 31, 2005
  3. fBechmann
    Replies:
    0
    Views:
    421
    fBechmann
    Jun 10, 2004
  4. Replies:
    7
    Views:
    3,336
    James Kanze
    Feb 12, 2008
  5. Sfdesigner Sfdesigner
    Replies:
    5
    Views:
    187
    Chris Shea
    Aug 13, 2007
Loading...

Share This Page