複製一個新的模板,複製成功則返回該模板的名稱

2019-04-13 20:57发布

///
        /// 複製一個新的模板,複製成功則返回該模板的名稱
        ///

        ///
        ///
        public string CopyTempLate(string templatePath)
        {
            try
            {
                if (!Directory.Exists(System.IO.Path.GetDirectoryName(templatePath) + "\TEMP"))
                {
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(templatePath) + "\TEMP");
                }
                string NewWord = System.IO.Path.GetDirectoryName(templatePath) + "\TEMP\SYS_" + Guid.NewGuid().ToString().ToUpper() + "_TEMP.doc";
                if (!File.Exists(NewWord))
                {
                    File.Copy(templatePath, NewWord, false);
                    return NewWord;
                }
                else
                {
                    NewWord = System.IO.Path.GetDirectoryName(templatePath) + "\TEMP\SYS_" + Guid.NewGuid().ToString().ToUpper() + "_TEMP.doc";
                    File.Copy(templatePath, NewWord, false);
                    return NewWord;
                }
            }
            catch (Exception ex)
            {
                return "";
            }
        }