static void Main(string[] args) { string s1 = ""; CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("your account", "your key"), true); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference("t11"); CloudFileDirectory rootDir = share.GetRootDirectoryReference(); CloudFile file = rootDir.GetFileReference("test.txt"); if (file.Exists()) { using (var ms = new MemoryStream()) { long?offset = Convert.ToInt64(file.Properties.Length * .8); long?length = Convert.ToInt64(file.Properties.Length * .20); file.DownloadRangeToStream(ms, offset, length); //set the position of memory stream to zero ms.Position = 0; using (var sr = new StreamReader(ms)) { s1 = sr.ReadToEnd(); } Console.WriteLine(s1); } } Console.WriteLine("---done---"); Console.ReadLine(); }
public void ValidateShareReadableWithSasToken(CloudFileShare share, string fileName, string sasToken) { Test.Info("Verify share read permission"); CloudFile file = share.GetRootDirectoryReference().GetFileReference(fileName); if (!file.Exists()) { PrepareFileInternal(file, null); } CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(share.ServiceClient.Credentials.AccountName, sasToken); CloudFileClient sasClient = sasAccount.CreateCloudFileClient(); CloudFileShare sasShare = sasClient.GetShareReference(share.Name); CloudFile sasFile = sasShare.GetRootDirectoryReference().GetFileReference(fileName); sasFile.FetchAttributes(); long buffSize = sasFile.Properties.Length; byte[] buffer = new byte[buffSize]; MemoryStream ms = new MemoryStream(buffer); sasFile.DownloadRangeToStream(ms, 0, buffSize); string md5 = Utility.GetBufferMD5(buffer); TestBase.ExpectEqual(sasFile.Properties.ContentMD5, md5, "content md5"); }
public string FetchFileMD5(CloudFile file) { using (MemoryStream ms = new MemoryStream()) { file.DownloadRangeToStream(ms, null, null); MD5 md5Computer = MD5.Create(); ms.Seek(0, SeekOrigin.Begin); return(Convert.ToBase64String(md5Computer.ComputeHash(ms))); } }
/// <summary> /// Validate the read permission in the sas token for the the specified file /// </summary> public void ValidateFileReadableWithSasToken(CloudFile file, string sasToken) { Test.Info("Verify file read permission"); CloudFile sasFile = new CloudFile(file.Uri, new StorageCredentials(sasToken)); sasFile.FetchAttributes(); long buffSize = sasFile.Properties.Length; byte[] buffer = new byte[buffSize]; MemoryStream ms = new MemoryStream(buffer); sasFile.DownloadRangeToStream(ms, 0, buffSize); string md5 = Utility.GetBufferMD5(buffer); TestBase.ExpectEqual(sasFile.Properties.ContentMD5, md5, "content md5"); }