Example #1
0
        /// <summary>
        /// 二进制数组Byte[]生成文件,并验证文件是否存在,存在则先删除
        /// </summary>
        /// <param name="createFileFullPath"></param>
        /// <param name="streamByte"></param>
        /// <param name="fileExistsDelete"></param>
        /// <returns></returns>
        public static bool ByteStreamToFile(string createFileFullPath, byte[] streamByte, bool fileExistsDelete)
        {
            if (File.Exists(createFileFullPath) && fileExistsDelete && !MdFileHelper.DeleteFile(createFileFullPath))
            {
                return(false);
            }
            FileStream fileStream = File.Create(createFileFullPath);

            fileStream.Write(streamByte, 0, streamByte.Length);
            fileStream.Close();
            return(true);
        }
Example #2
0
        /// <summary>
        /// 返回Excel 连接字符串
        /// </summary>
        /// <param name="excelPath"></param>
        /// <param name="header"></param>
        /// <param name="eType"></param>
        /// <param name="imex"></param>
        /// <returns></returns>
        public static string GetExcelConnectstring(string excelPath, bool header, MdExcelHelper.ExcelType eType, MdExcelHelper.IMEXType imex)
        {
            if (!MdFileHelper.IsExistFile(excelPath))
            {
                throw new FileNotFoundException("Excel路径不存在!");
            }
            string text = "NO";

            if (header)
            {
                text = "YES";
            }
            string result;

            if (eType == MdExcelHelper.ExcelType.Excel2003)
            {
                result = string.Concat(new object[]
                {
                    "Provider=Microsoft.Jet.OleDb.4.0; data source=",
                    excelPath,
                    ";Extended Properties='Excel 8.0; HDR=",
                    text,
                    "; IMEX=",
                    imex.GetHashCode(),
                    "'"
                });
            }
            else
            {
                result = string.Concat(new object[]
                {
                    "Provider=Microsoft.ACE.OLEDB.12.0; data source=",
                    excelPath,
                    ";Extended Properties='Excel 12.0 Xml; HDR=",
                    text,
                    "; IMEX=",
                    imex.GetHashCode(),
                    "'"
                });
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 复制文件
        /// </summary>
        /// <param name="sources"></param>
        /// <param name="dest"></param>
        public static void MoveFile(string sources, string dest)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(sources);

            FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos();
            for (int i = 0; i < fileSystemInfos.Length; i++)
            {
                FileSystemInfo fileSystemInfo = fileSystemInfos[i];
                string         text           = Path.Combine(dest, fileSystemInfo.Name);
                if (fileSystemInfo is FileInfo)
                {
                    File.Move(fileSystemInfo.FullName, text);
                }
                else
                {
                    Directory.CreateDirectory(text);
                    MdFileHelper.MoveFile(fileSystemInfo.FullName, text);
                }
            }
        }