コード例 #1
0
        /// <summary>
        /// Retrieve <see cref="FileInfo"/> data from <c>path</c>.
        /// </summary>
        /// <param name="path"></param>
        /// <returns>
        /// <see cref="FileInfo"/>
        /// </returns>
        public static FileInfo GetFileInfoFromPath(string path)
        {
            ExceptionThrow.IfNullOrEmpty(path, "path");
            ExceptionThrow.IfFileNotFound(path, "path");

            return(new FileInfo(path));
        }
コード例 #2
0
        /// <summary>
        /// Create an <see cref="AttachmentData"/> from <c>path</c>.
        /// </summary>
        /// <param name="path">File full path (with <c>drive\folder\filename.extension</c>)</param>
        /// <param name="fileName">If you want override filename on CRM please provide that. Otherwise leave blank.</param>
        /// <returns>
        /// <see cref="AttachmentData"/>
        /// </returns>
        public static AttachmentData CreateFromPath(string path, string fileName)
        {
            ExceptionThrow.IfNullOrEmpty(path, "path");
            ExceptionThrow.IfFileNotFound(path, "path");

            FileInfo fileInfo = new FileInfo(path);

            byte[] fileByte = File.ReadAllBytes(path);

            AttachmentData result = new AttachmentData()
            {
                Data = new AttachmentFileData()
                {
                    Base64    = fileByte.ToBase64String(),
                    ByteArray = fileByte
                },
                Meta = new AttachmentFileMeta
                {
                    Directory = fileInfo.Directory.FullName,
                    Extension = fileInfo.Extension,
                    FullPath  = fileInfo.FullName,
                    MimeType  = MimeMapping.GetMimeMapping(fileInfo.Name),
                    Name      = !string.IsNullOrEmpty(fileName) ? fileName : fileInfo.Name,
                    Size      = fileByte.Length
                }
            };

            return(result);
        }