Beispiel #1
0
        private void Initialize()
        {
            _shareClient.CreateIfNotExists();

            // Track the remaining directories to walk, starting from the root
            var remaining = new Queue <ShareDirectoryClient>();

            remaining.Enqueue(_shareClient.GetRootDirectoryClient());
            while (remaining.Count > 0)
            {
                // Get all of the next directory's files and subdirectories
                var dir = remaining.Dequeue();

                _shareDirectories.Add(HttpUtility.UrlDecode(dir.Path));
                foreach (var item in dir.GetFilesAndDirectories())
                {
                    // Keep walking down directories
                    if (item.IsDirectory)
                    {
                        remaining.Enqueue(dir.GetSubdirectoryClient(item.Name));
                    }
                    else
                    {
                        if (item.FileSize != null)
                        {
                            _shareFiles.Add(new ShareFileMetadata(item.Name, HttpUtility.UrlDecode(dir.Path), item.FileSize.Value));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void Initialize()
        {
            _shareClient.CreateIfNotExists();

            var remaining = new Queue <ShareDirectoryClient>();

            remaining.Enqueue(_shareClient.GetRootDirectoryClient());
            while (remaining.Count > 0)
            {
                var dir = remaining.Dequeue();

                _shareDirectories.Add(HttpUtility.UrlDecode(dir.Path));
                foreach (var item in dir.GetFilesAndDirectories())
                {
                    if (item.IsDirectory)
                    {
                        remaining.Enqueue(dir.GetSubdirectoryClient(item.Name));
                    }
                    else
                    if (item.FileSize != null)
                    {
                        _shareFiles.Add(new ShareFileMetadata(item.Name, HttpUtility.UrlDecode(dir.Path) ?? string.Empty, item.FileSize.Value));
                    }
                }
            }
        }
Beispiel #3
0
        public static ShareFileClient GetAzureFile(string folderName, string fileName)
        {
            string shareName = MyWebUtils.Application.ToLower();

            string connectionString = Properties.Settings.Default.StorageConnectionString;

            ShareClient share = new ShareClient(connectionString, shareName);

            // Create the share if it doesn't already exist
            share.CreateIfNotExists();

            if (share.Exists())
            {
                ShareDirectoryClient subFolder = share.GetRootDirectoryClient();

                foreach (string subFolderName in folderName.Split('\\'))
                {
                    subFolder = subFolder.GetSubdirectoryClient(subFolderName);
                    subFolder.CreateIfNotExists();
                }

                return(subFolder.GetFileClient(fileName));
            }

            return(null);
        }
        public async Task <StoreFileInfo> UploadFile(UploadDataInfo uploadInfo)
        {
            // Azure request only lowerCase container name
            string container = uploadInfo.Container.ToLower();

            // Get a reference to a share and then create it
            ShareClient share = new ShareClient(this.connection, container);

            share.CreateIfNotExists();

            // Get a reference to a directory and create it
            ShareDirectoryClient directory = share.GetDirectoryClient(uploadInfo.DirectoryName);
            await directory.CreateIfNotExistsAsync();

            // Get a reference to a file and upload it
            ShareFileClient          file       = directory.GetFileClient(this.GenerateFileName(uploadInfo.FileName));
            Response <ShareFileInfo> uploadFile = file.Create(uploadInfo.Stream.Length);

            file.UploadRange(
                new HttpRange(0, uploadInfo.Stream.Length),
                uploadInfo.Stream);

            return(new StoreFileInfo(string.Empty, uploadFile.Value.SmbProperties.FileId));
        }