Check out System.IO.Path.GetTempFileName().
As this call will also create the file, you may have to delete it prior to
compacting.
Ex:
string dbPath = "myDatabase.mdb";
string tempPath = Path.GetTempFileName();
File.Delete(tempPath); //0 byte file created by GetTempFileName
//compact database
File.Delete(dbPath);
File.Move(tempPath, dbPath);
--
Adam Clauss
(E-Mail Removed)
"jez123456" <(E-Mail Removed)> wrote in message
news:91EFE650-AE5F-4AA6-9BB6-(E-Mail Removed)...
> Hi, I've written a c# program to compact certain msaccess databases. The
> way
> this works is to compact say C:\test1.mdb to C:\temp.mdb, then delete
> C:\test1.mdb and rename C:\temp.mdb as C:\test1.mdb.
>
> My problem occurs if there is already a C:\temp.mdb file. I don't want to
> just delete this, as it could have been created separately by a user.
>
> In my code, I set a constant as follows:
>
> private const string tempMdb = @"C:\temp.mdb";
>
> To check that the file exists, I can use
>
> if (File.Exists(tempMdb))...
>
> but, if it is present, how do I change the tempMdb to a unique name?
>
> I.e. if C:\temp.mdb is present, then rename as C:\temp1.mdb,
> if C:\temp1.mdb is present, then rename as C:\temp2.mdb,
> if C:\temp2.mdb is present, then rename as C:\temp3.mdb.....
>
> I realise some sort of looping maybe required here but I'm not sure on the
> best approach.
>
> Thanks in advance.
>