コード例 #1
0
ファイル: DVR.cs プロジェクト: mutita/anpr
        /// <summary>
        /// Creates a copy of the file in a temp directory and give it a unique file name. The file is cleaned up ater 10 minutes.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public string GetUniqueCopy(string file)
        {
            /// the email server has a problem that if you attach a file to a new mail, and then
            /// send multiple emails with the same attachment, you get an exception of file open by another process.
            ///  so create a new file copy for each mail that is sent. Don't keep this file around forever.
            ///

            string temppath = Paths.GetTempDirectory();

            FileInfo fi = new FileInfo(file);

            // remove the exention
            string[] sp1      = fi.Name.Split('.');
            string   nameOnly = sp1[0];


            string newname = nameOnly + m_UniqueSerialNumber.ToString() + "." + sp1[1];

            m_UniqueSerialNumber++;

            newname = temppath + "\\" + newname;
            try
            {
                //  File.Copy(file, newname);
                FileAccessControl.FileCopy(file, newname);

                TEMPFILES tempFileInfo = new TEMPFILES();
                tempFileInfo.path        = newname;
                tempFileInfo.timeCreated = DateTime.Now;

                m_TempFileList.Add(tempFileInfo);
            }
            catch { }

            return(newname);
        }
コード例 #2
0
ファイル: DVR.cs プロジェクト: anndream/anpr-1
        /// <summary>
        /// Creates a copy of the file in a temp directory and give it a unique file name. The file is cleaned up ater 10 minutes.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public string GetUniqueCopy(string file)
        {
            /// the email server has a problem that if you attach a file to a new mail, and then
            /// send multiple emails with the same attachment, you get an exception of file open by another process.
            ///  so create a new file copy for each mail that is sent. Don't keep this file around forever.
            ///

            string temppath = Paths.GetTempDirectory();

            FileInfo fi = new FileInfo(file);

            // remove the exention
            string[] sp1 = fi.Name.Split('.');
            string nameOnly = sp1[0];

            string newname = nameOnly + m_UniqueSerialNumber.ToString() + "." + sp1[1];

            m_UniqueSerialNumber++;

            newname = temppath + "\\" + newname;
            try
            {
                //  File.Copy(file, newname);
                FileAccessControl.FileCopy(file, newname);

                TEMPFILES tempFileInfo = new TEMPFILES();
                tempFileInfo.path = newname;
                tempFileInfo.timeCreated = DateTime.Now;

                m_TempFileList.Add(tempFileInfo);
            }
            catch { }

            return (newname);
        }