public string GetNextIndexedFileName(string fileName, bool createFolder) { string extension = Path.GetExtension(fileName); string result = "0001" + extension; bool fileDirectoryExists = fileDirectory.Exists(); if (createFolder && !fileDirectoryExists) { fileDirectory.Create(); fileDirectoryExists = true; } if (fileDirectoryExists) { var directoryFiles = fileDirectory.ListFilesAndDirectories(); foreach (IListFileItem directoryFile in directoryFiles) { string oneFile = directoryFile.Uri.ToString(); string oneFile1 = directoryFile.StorageUri.ToString(); } /*string lastFileName = directoryFiles. .LastOrDefault(); * * try * { * int lastIndex = Convert.ToInt32(Path.GetFileNameWithoutExtension(lastFileName)); * * result = (lastIndex + 1).ToString().PadLeft(4, '0') + extension; * } * catch (Exception ex) * { * //Do nothing * } * * * * * * // Get a reference to the file we created previously. * CloudFile file = fileDirectory.GetFileReference(fileName); * * // Ensure that the file exists. * if (file.Exists()) * { * }*/ } return(result); }
static void Main(string[] args) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection); CloudFileClient cloudFileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare fileShare = cloudFileClient.GetShareReference("doc2020"); // Ensure that the share exists. if (fileShare.Exists()) { // Get a reference to the root directory for the share. CloudFileDirectory fileDirectory = fileShare.GetRootDirectoryReference(); // Get a reference to the directory we created previously. CloudFileDirectory customDirectory = fileDirectory.GetDirectoryReference("storage"); // Ensure that the directory exists. if (customDirectory.Exists()) { // Get a reference to the file we created previously. CloudFile fileInfo = customDirectory.GetFileReference("Log1.txt"); // Ensure that the file exists. if (fileInfo.Exists()) { // Write the contents of the file to the console window. Console.WriteLine(fileInfo.DownloadTextAsync().Result); } } NewFileCreate(); } }
private CloudFileDirectory ConnectToDirectory(CloudFileShare share, string dir) { CloudFileDirectory rootDirectory = share.GetRootDirectoryReference(); CloudFileDirectory epubsDirectory = rootDirectory.GetDirectoryReference(dir); return(!epubsDirectory.Exists() ? null : epubsDirectory); }
private CloudFile GetCloudFileReference(string path, bool createIfNotExist = false) { CloudFileDirectory directory = cloudFileClient.GetShareReference(rootDir).GetRootDirectoryReference(); CloudFile file = null; string[] folders = GetArrrayOfFolders(path); for (int i = 0; i < folders.Length; i++) { if (i == folders.Length - 1) { file = directory.GetFileReference(folders[i]); if (!file.Exists() && createIfNotExist) { file.Create(0L); } } else { directory = directory.GetDirectoryReference(folders[i]); if (!directory.Exists() && createIfNotExist) { directory.Create(); } } } return(file); }
public async Task <List <FileContent> > GetCloudContent() { List <FileContent> lstFileContent = new List <FileContent>(); if (_cloudFileShare == null) { throw new NullReferenceException(nameof(_cloudFileShare)); } if (_cloudFileShare.Exists()) { CloudFileDirectory cloudRootDirectory = _cloudFileShare.GetRootDirectoryReference(); if (cloudRootDirectory.Exists()) { var lstFilesAndDirectories = cloudRootDirectory.ListFilesAndDirectories(); foreach (var file in lstFilesAndDirectories) { if (file is CloudFile) { CloudFile cloudFile = file as CloudFile; var fileContent = await ParseFileContent(cloudFile); lstFileContent.Add(fileContent); MoveFileToProcessedFolder(cloudFile); } } } } return(lstFileContent); }
public void AzureFile_Crud() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); Assert.NotNull(storageAccount); // Create a CloudFileClient object for credentialed access to Azure Files. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference("bma"); // Ensure that the share exists. if (share.Exists()) { // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory we created previously. CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("bma"); // Ensure that the directory exists. if (sampleDir.Exists()) { // Get a reference to the file we created previously. CloudFile file = sampleDir.GetFileReference("function.json"); Assert.AreEqual(true, file.Exists()); file. } } }
public void ValidateShareCreateableWithSasToken(CloudFileShare share, string sastoken) { Test.Info("Verify share create permission"); string fileName = Utility.GenNameString("file"); string dirName = Utility.GenNameString("dir"); int fileLength = 10; CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(share.ServiceClient.Credentials.AccountName, sastoken); CloudFileShare sasShare = sasAccount.CreateCloudFileClient().GetShareReference(share.Name); if (!share.Exists()) { sasShare.Create(); Test.Assert(sasShare.Exists(), "The share should exist after Creating with sas token"); } CloudFileDirectory dir = share.GetRootDirectoryReference().GetDirectoryReference(dirName); CloudFileDirectory sasDir = sasShare.GetRootDirectoryReference().GetDirectoryReference(dirName); sasDir.Create(); Test.Assert(dir.Exists(), "The directory should exist after Creating with sas token"); CloudFile file = dir.GetFileReference(fileName); CloudFile sasFile = sasDir.GetFileReference(fileName); sasFile.Create(fileLength); Test.Assert(file.Exists(), "The file should exist after Creating with sas token"); TestBase.ExpectEqual(fileLength, file.Properties.Length, "File Lenth should match."); }
public async Task JokeIntent(IDialogContext context, LuisResult result) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( Microsoft.Azure.CloudConfigurationManager.GetSetting("cosmostorageaccount_AzureStorageConnectionString")); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference("files"); if (share.Exists()) { CloudFileDirectory rootDir = share.GetRootDirectoryReference(); CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("AstroFiles"); if (sampleDir.Exists()) { CloudFile sourceFile = sampleDir.GetFileReference("Joke.txt"); if (sourceFile.Exists()) { if (countjoke == 0) { await context.PostAsync("I've got one for you: "); } countjoke++; var lines = string.Format(sourceFile.DownloadText()); Random number = new Random(); int num = number.Next(1, 64); var linesArray = lines.Split('.'); await context.PostAsync($"{linesArray[num]}"); } } } }
public async Task FactIntent(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( Microsoft.Azure.CloudConfigurationManager.GetSetting("cosmostorageaccount_AzureStorageConnectionString")); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference("files"); if (share.Exists()) { CloudFileDirectory rootDir = share.GetRootDirectoryReference(); CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("AstroFiles"); if (sampleDir.Exists()) { CloudFile sourceFile = sampleDir.GetFileReference("Facts.txt"); if (sourceFile.Exists()) { if (countfact == 0) { await context.PostAsync("Here's something interesting:"); } countfact++; var lines = string.Format(sourceFile.DownloadText()); var linesArray = lines.Split('.'); Random number = new Random(); int num = number.Next(1, 57); await context.PostAsync($"{linesArray[num]}"); } } } }
static void Main(string[] args) { CloudStorageAccount cuentaAlmacenamiento = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("FileConnectionString")); CloudFileClient clienteArchivos = cuentaAlmacenamiento.CreateCloudFileClient(); CloudFileShare archivoCompartido = clienteArchivos.GetShareReference("platzifile"); if (archivoCompartido.Exists()) { CloudFileDirectory carpetaRaiz = archivoCompartido.GetRootDirectoryReference(); CloudFileDirectory directorio = carpetaRaiz.GetDirectoryReference(DIRECTORIO_NOMBRE); if (directorio.Exists()) { Console.WriteLine($"Archivo a leer: {ARCHIVO_NOMBRE}"); CloudFile archivo = directorio.GetFileReference(ARCHIVO_NOMBRE); if (archivo.Exists()) { Console.WriteLine(archivo.DownloadTextAsync().Result); } else { Console.WriteLine($"no se encontro el archivo: {ARCHIVO_NOMBRE}"); } } else { Console.WriteLine($"no se encontro la carpeta: {DIRECTORIO_NOMBRE}"); } } Console.ReadLine(); }
public MemoryStream GetCloudFileStream(string fileDirectory, string fileName) { MemoryStream memstream = new MemoryStream(); try { fileDirectory = CleanRelativeCloudDirectoryName(fileDirectory); CloudStorageAccount cloudStorageAccount = GetCloudStorageAccount(); CloudFileClient fileClient = GetCloudFileClient(cloudStorageAccount); CloudFileShare share = GetCloudFileShareReference(fileClient); CloudFileDirectory shareDir = GetCloudFileDirectory(share, fileDirectory); if ((shareDir != null) && shareDir.Exists()) { CloudFile file = GetCloudFile(shareDir, fileName); if (file != null) { file.DownloadToStream(memstream); } } } catch (Exception oExeption) { oExeption.Log($"GetCloudFileStream- {fileName}"); } return(memstream); }
static void Main(string[] args) { CloudStorageAccount CuentaAlmacenamiento = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CadenaConexion")); CloudFileClient ClienteArchivos = CuentaAlmacenamiento.CreateCloudFileClient(); CloudFileShare ArchivoCompartido = ClienteArchivos.GetShareReference("filepleon"); if (ArchivoCompartido.Exists()) { CloudFileDirectory CarpetaRaiz = ArchivoCompartido.GetRootDirectoryReference(); CloudFileDirectory Directorio = CarpetaRaiz.GetDirectoryReference("Archivos"); if (Directorio.Exists()) { CloudFile Archivo = Directorio.GetFileReference("prueba.txt"); if (Archivo.Exists()) { Console.WriteLine(Archivo.DownloadTextAsync().Result); Console.ReadLine(); } } } }
private async Task <T> AccessToFileAsync <T>(string filePath, Func <CloudFile, Task <T> > delFunction) { var azureFile = AzureFilePath.FromFilePath(filePath); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference(azureFile.ShareReference); // Ensure that the share exists. if (true || await share.ExistsAsync().ConfigureAwait(false)) //Obviamos esta comprobación porque puede que no se tenga privilegios suficientes { // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory we created previously. if (azureFile.Folders.Any()) { CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(azureFile.Folders[0]); if (!sampleDir.Exists()) { throw new Exception("Incorrect route path."); } for (int i = 1; i < azureFile.Folders.Count; i++) { sampleDir = sampleDir.GetDirectoryReference(azureFile.Folders[i]); if (!sampleDir.Exists()) { throw new Exception("Incorrect route path."); } } CloudFile file = sampleDir.GetFileReference(azureFile.FileName); // Ensure that the file exists. return(await delFunction(file).ConfigureAwait(false)); } else { CloudFile file = rootDir.GetFileReference(azureFile.FileName); // Ensure that the file exists. return(await delFunction(file).ConfigureAwait(false)); } } else { throw new Exception("Share not found."); } }
public void Init() { _root = _share.GetRootDirectoryReference(); if (!_root.Exists()) { _root.Create(); } }
public CloudFileDirectory GetFileShare(string dirname, bool createIfDoesntExist = false) { var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storagekey"]); var fileClient = storageAccount.CreateCloudFileClient(); var folderPath = dirname.Split('\\'); //ex: fileupload\uploads CloudFileShare share = fileClient.GetShareReference(folderPath[0]); CloudFileDirectory directory = null; if (!share.Exists()) { throw new InvalidOperationException(string.Format("{0}share doesnt exists.", folderPath[0])); } directory = share.GetRootDirectoryReference(); if (!createIfDoesntExist) { //Avoid loop if directory neednt be created if (folderPath.Length > 1) { directory = directory.GetDirectoryReference(string.Join("/", folderPath.Skip(1))); } } else { //Loop if directories need to be checked for existance for (int i = 1; i < folderPath.Length && directory.Exists(); i++) { directory = directory.GetDirectoryReference(folderPath[i]); //Create if directory doesnt exists if (!directory.Exists()) { directory.Create(); } } } if (directory.Exists()) { return(directory); } throw new InvalidOperationException(string.Format("{0} directory doesnt exists.", directory.Name)); }
public string GetFileFromFileStorage() { try { string returnString = "No data retreived."; string accountName = "storagemartin"; string accountKey = ConfigurationManager.AppSettings["BlobPassword"]; StorageCredentials creds = new StorageCredentials(accountName, accountKey); CloudStorageAccount storageAccount = new CloudStorageAccount(creds, useHttps: true); // Create a CloudFileClient object for credentialed access to Azure Files. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference("tipslogs"); // Ensure that the share exists. if (share.Exists()) { // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory we created previously. CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("thetipslogs"); // Ensure that the directory exists. if (sampleDir.Exists()) { // Get a reference to the file we created previously. CloudFile file = sampleDir.GetFileReference("tipslogError.txt"); // Ensure that the file exists. if (file.Exists()) { // Write the contents of the file to the console window. returnString = file.DownloadTextAsync().Result; returnString = MakeHtmlFriendlyText(returnString); return(returnString); } } } return(returnString); } catch (Exception e) { string inner = e.InnerException != null?e.InnerException.ToString() : "NULL"; return(string.Format("Error in method GetFileFromFileStorage. Exception: {0}. Inner: {1}", e.Message.ToString(), inner)); } }
private IExecutionResult RemoveDirectoryInternal(Action removeDirectoryAction, CloudFileDirectory dirToBeRemovedForValidation = null) { removeDirectoryAction(); var result = CommandAgent.Invoke(); if (dirToBeRemovedForValidation != null) { CommandAgent.AssertNoError(); result.AssertNoResult(); Test.Assert(!dirToBeRemovedForValidation.Exists(), "Directory should not exist after removed."); } return(result); }
private void CreateParentDirectoryIfNotExists(CloudFile file) { FileRequestOptions fileRequestOptions = Transfer_RequestOptions.DefaultFileRequestOptions; CloudFileDirectory parent = file.Parent; if (!this.IsLastDirEqualsOrSubDirOf(parent)) { if (!parent.Exists(fileRequestOptions)) { CreateCloudFileDirectoryRecursively(parent); } this.lastAzureFileDirectory = parent; } }
public void CreateDirectory(string name) { CloudFileDirectory directory = cloudFileClient.GetShareReference(rootDir).GetRootDirectoryReference(); string[] folders = GetArrrayOfFolders(name); foreach (string folder in folders) { directory = directory.GetDirectoryReference(folder); if (!directory.Exists()) { directory.Create(); } } }
internal void CreateDirectoryAndShare(CloudFileDirectory dir) { var share = dir.Share; if (!share.Exists()) { share.Create(); } CreateParentDirectory(dir, share.GetRootDirectoryReference()); if (!dir.Exists()) { dir.Create(); } }
private void WriteLogLine(WriteWay writeWay, string writeLogLine, params string[] logFilePath) { if (logFilePath.Length < 2) { Console.WriteLine(invalidExistLogFilePath); return; } CloudStorageAccount storageAccount = CloudStorageAccount.Parse( string.Format(@"DefaultEndpointsProtocol=https;AccountName={0}; AccountKey={1};EndpointSuffix=core.windows.net", Constant.LOGGER_ACCOUNT_NAME, Constant.Instance.StorageAccountKey)); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference(logFilePath[0]); if (!share.Exists()) { share.Create(); } CloudFileDirectory sampleDir = share.GetRootDirectoryReference(); for (int i = 1; i < logFilePath.Length - 1; i++) { CloudFileDirectory nextLevelDir = sampleDir.GetDirectoryReference("TestLogs"); if (!sampleDir.Exists()) { sampleDir.Create(); } sampleDir = nextLevelDir; } CloudFile file = sampleDir.GetFileReference(logFilePath[logFilePath.Length - 1]); string writenLineContent = ""; if (file.Exists()) { if (writeWay == WriteWay.Cover) { } else if (writeWay == WriteWay.Append) { writenLineContent = file.DownloadTextAsync().Result; } } file.UploadText(writenLineContent + writeLogLine + "\n"); }
private async void MoveFileToProcessedFolder(CloudFile cloudFile) { CloudFileDirectory rootDirectory = _cloudFileShare.GetRootDirectoryReference(); if (rootDirectory.Exists()) { CloudFileDirectory customDirectory = rootDirectory.GetDirectoryReference(_azureFileProcessedFolderName); customDirectory.CreateIfNotExists(); var fileName = $"{Path.GetFileNameWithoutExtension(cloudFile.Name)}-{DateTime.Now.ToString(_appendDateFormatInFileName)}{Path.GetExtension(cloudFile.Name)}"; CloudFile file = customDirectory.GetFileReference(fileName); Uri fileUrl = new Uri(cloudFile.StorageUri.PrimaryUri.ToString()); await file.StartCopyAsync(fileUrl); await cloudFile.DeleteAsync(); } }
public static void DownloadFile(string path) { var value = path; if (value != null && value != "") { string[] fname = value.Split('/'); string foldername = ""; int count = 0; for (int i = fname.Length - 2; i <= (fname.Length - 2); i--) { if (i != 0) { count++; foldername += fname[count] + '/'; } else { break; } } //get share name string ShareName = fname[0].ToLower(); CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudFileClient cloudFileClient = cloudStorageAccount.CreateCloudFileClient(); CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(ShareName); CloudFileDirectory root = cloudFileShare.GetRootDirectoryReference(); CloudFileDirectory directoryToUse = root.GetDirectoryReference(foldername); CloudFile cloudFile = directoryToUse.GetFileReference(fname.Last()); //checking for file exist on directory or not if (directoryToUse.Exists()) { //if yes store it to local path of your project with given file name var memStream = new MemoryStream(); using (var fileStream = System.IO.File.OpenWrite(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Download.pdf"))) { cloudFile.DownloadToStream(memStream); } Console.WriteLine("File saved in {0}", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Download.pdf")); Console.ReadLine(); } else { Console.WriteLine("File not exist on Azure."); } } }
static void Main(string[] args) { string accountname = "xxx"; string accountkey = "xxxxxxx"; CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountname, accountkey), true); // Create a CloudFileClient object for credentialed access to Azure Files. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share. CloudFileShare share = fileClient.GetShareReference("s66"); //if fileshare does not exist, create it. share.CreateIfNotExists(); if (share.Exists()) { // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory. CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("CustomLogs"); //if the directory does not exist, create it. sampleDir.CreateIfNotExists(); if (sampleDir.Exists()) { // Get a reference to the file. CloudFile file = sampleDir.GetFileReference("Log1.txt"); // if the file exists, read the content of the file. if (file.Exists()) { // Write the contents of the file to the console window. Console.WriteLine(file.DownloadTextAsync().Result); } //if the file does not exist, create it with size == 500bytes else { file.Create(500); } } } Console.WriteLine("--file share test--"); Console.ReadLine(); }
CloudFile GetDirectoryIndexFile() { if (rootDirectory != null) { if (!rootDirectory.Exists()) { return(null); } var indexDirectory = rootDirectory.GetDirectoryReference(".indexes"); indexDirectory.CreateIfNotExists(); var indexFile = indexDirectory.GetFileReference("directories.index"); return(indexFile); } return(null); }
public static void OutputLogContent(params string[] logFilePath) { if (logFilePath.Length < 2) { Console.WriteLine(invalidExistLogFilePath); return; } CloudStorageAccount storageAccount = CloudStorageAccount.Parse( string.Format(@"DefaultEndpointsProtocol=https;AccountName={0}; AccountKey={1};EndpointSuffix=core.windows.net", Constant.LOGGER_ACCOUNT_NAME, Constant.Instance.StorageAccountKey)); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference(logFilePath[0]); if (!share.Exists()) { Console.WriteLine(invalidExistLogFilePath); return; } CloudFileDirectory sampleDir = share.GetRootDirectoryReference(); for (int i = 1; i < logFilePath.Length - 1; i++) { CloudFileDirectory nextLevelDir = sampleDir.GetDirectoryReference(logFilePath[i]); if (!sampleDir.Exists()) { Console.WriteLine(invalidExistLogFilePath); return; } sampleDir = nextLevelDir; } CloudFile file = sampleDir.GetFileReference(logFilePath[logFilePath.Length - 1]); if (file.Exists()) { Console.WriteLine(file.DownloadTextAsync().Result); } else { Console.WriteLine(); } }
/* * GetAppendBlobReference is removed from Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer * So we cannot release the log function based on the append function from Microsoft.WindowsAzure.Storage. * stackoverflow: https://stackoverflow.com/questions/48411359/getappendblobreference-is-removed-from-microsoft-windowsazure-storage-blob-cloud */ public static void MainMethod() { string accountName = ""; string accountKey = ""; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(string.Format(@"DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountName, accountKey)); // Create a CloudFileClient object for credentialed access to Azure Files. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference("logs"); // If the share does not exist, create it. if (!share.Exists()) { share.Create(); } // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory we created previously. CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("TestLogs"); if (!sampleDir.Exists()) { sampleDir.Create(); } // Get a reference to the file we created previously. CloudFile file = sampleDir.GetFileReference("Log1.txt"); // Ensure that the file exists. if (file.Exists()) { // Write the contents of the file to the console window. Console.WriteLine(file.DownloadTextAsync().Result); file.UploadText("12345"); Console.WriteLine(file.DownloadTextAsync().Result); } else { file.UploadText("1234"); } Console.ReadKey(); }
public static void getFolderFromAzureToLocalPath(string absolutePath, string sdxRoot, string sessionId, string AzCopyPath, string connectionString, string connectionKey) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference("smvautomation"); CloudFileDirectory direc = share.GetRootDirectoryReference(); absolutePath = absolutePath.ToLower(); sdxRoot = sdxRoot.ToLower(); string relativePath = absolutePath.Replace(sdxRoot, "%SDXROOT%"); string cloudPath = Path.Combine(sessionId, "Logs", relativePath, "Bugs"); Console.WriteLine(cloudPath); CloudFileDirectory dir = direc.GetDirectoryReference(cloudPath); absolutePath = Path.Combine(absolutePath, "Bugs"); if (Directory.Exists(absolutePath)) { Directory.Delete(absolutePath, true); } if (dir.Exists()) { Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.CreateNoWindow = false; cmd.StartInfo.UseShellExecute = false; cmd.Start(); string changeLocation = "cd " + AzCopyPath; cmd.StandardInput.WriteLine(changeLocation); string command = @".\AzCopy.exe /Source:https://smvtest.file.core.windows.net/smvautomation/" + cloudPath + " /Dest:" + absolutePath + " /Sourcekey:" + connectionKey + " /S /Z:" + absolutePath; cmd.StandardInput.WriteLine(command); cmd.StandardInput.WriteLine("exit"); cmd.WaitForExit(); } else { Console.WriteLine("Could not find bugs folder in the location!"); } }
public CloudFileDirectory CreateDirectory(CloudFileDirectory parent, string name) { try { CancelOperation = false; CloudFileDirectory cd = parent?.GetDirectoryReference(name); if (cd.Exists()) { throw new Exception("Folder already exists!"); } cd.Create(); return(cd); } catch (Exception ex) { return(null); } }
public void Copy_file_to_another_file() { // Parse the connection string for the storage account. StorageCredentials Credentials = new StorageCredentials(this.Account, this.Key); CloudStorageAccount storageAccount = new CloudStorageAccount(Credentials, false); // Create a CloudFileClient object for credentialed access to File storage. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference("logs"); // Ensure that the share exists. if (share.Exists()) { // Get a reference to the root directory for the share. CloudFileDirectory rootDir = share.GetRootDirectoryReference(); // Get a reference to the directory we created previously. CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("CustomLogs"); // Ensure that the directory exists. if (sampleDir.Exists()) { // Get a reference to the file we created previously. CloudFile sourceFile = sampleDir.GetFileReference("Log1.txt"); // Ensure that the source file exists. if (sourceFile.Exists()) { // Get a reference to the destination file. CloudFile destFile = sampleDir.GetFileReference("Log1Copy.txt"); // Start the copy operation. destFile.StartCopy(sourceFile); // Write the contents of the destination file to the console window. Console.WriteLine(destFile.DownloadText()); } } } }