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 void UploadFile(string localFilePath) { // Create a client to a file share ShareClient share = new ShareClient(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString, shareName); // Get a directory client on file share and create directory if not exists ShareDirectoryClient directory = share.GetDirectoryClient(directoryName); directory.CreateIfNotExists(); // Get a reference to a file and upload it ShareFileClient file = directory.GetFileClient(fileName); using (FileStream stream = File.OpenRead(localFilePath)) { file.Create(stream.Length); file.UploadRange( new HttpRange(0, stream.Length), stream); } }