/// <summary> /// Save file to website /// </summary> /// <param name="bytes">File content</param> /// <param name="name">Name for new file</param> /// <returns>url to file</returns> public static string UploadFile(byte[] bytes, string name) { name = name.ToLower(); var url = String.Format("{0}{1}", Context.StorageUrl, name); var storageType = GetStorageType(Context.StorageConnectionString); switch (storageType) { case Storage.FileSystem: { var path = String.Format("{0}{1}", Global.Context.StorageConnectionString, name); File.WriteAllBytes(path, bytes); break; } case Storage.WindowsAzureStorage: { throw new NotImplementedException(); ////Upload to Windows Azure Storage //var storageAccount = CloudStorageAccount.Parse(Context.FileStorageConnectionString); //var blobClient = storageAccount.CreateCloudBlobClient(); //// Retrieve a reference to a container. //var container = blobClient.GetContainerReference(Context.BlobContainerName); //// Retrieve reference to a blob named "myblob". //var blockBlob = container.GetBlockBlobReference(name); //// Create or overwrite the blob with contents from a file. //var stream = new MemoryStream(bytes); //blockBlob.UploadFromStream(stream); //url = blockBlob.Uri.ToString(); //break; } case Storage.Ftp: { var path = Context.StorageConnectionString + name; var ftp = new Ftp(); ftp.UploadFile(bytes, path); break; } case Storage.Unknown: { throw new Exception("Unknow storage type"); break; } } return(url); }
public bool RestarWebApplication() { var storageType = GetStorageType(Context.ApplicationStorageConnectionString); try { switch (storageType) { case Storage.FileSystem: { var path = Global.Context.ApplicationStorageConnectionString + "web.config"; var stream = File.Open(path, FileMode.Open); var streamWriter = new StreamWriter(stream); streamWriter.WriteLine("<!--restart-->"); stream.Close(); var text = File.ReadAllText(path).Replace("<!--restart-->", String.Empty); File.WriteAllText(path, text); break; } case Storage.WindowsAzureStorage: { throw new NotImplementedException(); break; } case Storage.Ftp: { var path = Context.ApplicationStorageConnectionString + "web.config"; var ftp = new Ftp(); var bytes = ftp.DownloadFile(path); //var result = System.Text.Encoding.UTF8.GetString(bytes); ftp.UploadFile(bytes, path); break; } case Storage.Unknown: { throw new Exception("Unknow storage type"); break; } } } catch { return(false); } return(true); }
public bool RestarWebApplication() { var storageType = GetStorageType(Context.WebsiteStorageConnectionString); try { switch (storageType) { case Storage.FileSystem: { var path = Global.Context.WebsiteStorageConnectionString + "web.config"; var stream = File.Open(path, FileMode.Open); var streamWriter = new StreamWriter(stream); streamWriter.WriteLine("<!--restart-->"); stream.Close(); var text = File.ReadAllText(path).Replace("<!--restart-->", String.Empty); File.WriteAllText(path, text); break; } case Storage.WindowsAzureStorage: { throw new NotImplementedException(); break; } case Storage.Ftp: { var path = Context.WebsiteStorageConnectionString + "web.config"; var ftp = new Ftp(); var bytes = ftp.DownloadFile(path); //var result = System.Text.Encoding.UTF8.GetString(bytes); ftp.UploadFile(bytes, path); break; } case Storage.Unknown: { throw new Exception("Unknow storage type"); break; } } } catch (Exception ex) { return false; } return true; }
/// <summary> /// Save file to website /// </summary> /// <param name="bytes">File content</param> /// <param name="name">Name for new file</param> /// <returns>url to file</returns> public static string UploadFile(byte[] bytes, string name) { name = name.ToLower(); var url = String.Format("{0}{1}", Context.FileStorageUrl, name); var storageType = GetStorageType(Context.FileStorageConnectionString); switch (storageType) { case Storage.FileSystem: { var path = String.Format("{0}{1}", Global.Context.FileStorageConnectionString, name); File.WriteAllBytes(path, bytes); break; } case Storage.WindowsAzureStorage: { //Upload to Windows Azure Storage var storageAccount = CloudStorageAccount.Parse(Context.FileStorageConnectionString); var blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. var container = blobClient.GetContainerReference(Context.BlobContainerName); // Retrieve reference to a blob named "myblob". var blockBlob = container.GetBlockBlobReference(name); // Create or overwrite the blob with contents from a file. var stream = new MemoryStream(bytes); blockBlob.UploadFromStream(stream); url = blockBlob.Uri.ToString(); break; } case Storage.Ftp: { var path = Context.FileStorageConnectionString + name; var ftp = new Ftp(); ftp.UploadFile(bytes, path); break; } case Storage.Unknown: { throw new Exception("Unknow storage type"); break; } } return url; }