jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
namespace HH.WMS.Utils.NPOI.Util
{
    using System;
    using System.Configuration;
    using System.IO;
    using System.Threading;
 
    public class TempFile
    {
        
 
        /**
         * Creates a temporary file.  Files are collected into one directory and by default are
         * deleted on exit from the VM.  Files can be kept by defining the system property
         * <c>poi.keep.tmp.files</c>.
         * 
         * Dont forget to close all files or it might not be possible to delete them.
         */
        public static FileInfo CreateTempFile(String prefix, String suffix)
        {
            
            //if (dir == null)
            //{
            //    dir = Directory.CreateDirectory(Path.GetTempPath()+@"\poifiles");               
            //}
            Random rnd = new Random(DateTime.Now.Millisecond);
            string file=prefix + rnd.Next() + suffix;
            FileStream newFile = File.Create(file);
            newFile.Close();
 
            return new FileInfo(file);
        }
 
        public static string GetTempFilePath(String prefix, String suffix)
        {
            //if (dir == null)
            //{
            //    dir = Directory.CreateDirectory(Path.GetTempPath() + @"\poifiles");
            //}
            Random rnd = new Random(DateTime.Now.Millisecond);
            Thread.Sleep(10);
            return prefix + rnd.Next() + suffix;
            //return dir.Name + "\\" + prefix + rnd.Next() + suffix;
        }
    }
}