public static DropboxInfo RetrieveDropboxInfo(string filename) { LOG.InfoFormat("Retrieving Dropbox info for {0}", filename); DropboxInfo dropBoxInfo = new DropboxInfo(); dropBoxInfo.ID = filename; dropBoxInfo.Title = filename; dropBoxInfo.Timestamp = DateTime.Now; dropBoxInfo.WebUrl = string.Empty; // get the config of dropbox Dropbox.DropBoxConfiguration dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as Dropbox.DropBoxConfiguration; // instanciate the cloudstorage manager CloudStorage storage = new CloudStorage(); // get the root entry of the cloud storage ICloudDirectoryEntry root = storage.GetRoot(); // open the connection to the storage storage.Open(dropBoxConfig, config.DropboxAccessToken); dropBoxInfo.WebUrl = storage.GetFileSystemObjectUrl(dropBoxInfo.ID, root).ToString(); ICloudFileSystemEntry fileSystemEntry = storage.GetFileSystemObject(dropBoxInfo.ID, root); if (fileSystemEntry != null) { dropBoxInfo.Title = fileSystemEntry.Name; dropBoxInfo.Timestamp = fileSystemEntry.Modified; } // close the cloud storage connection if (storage.IsOpened) { storage.Close(); } return dropBoxInfo; }
public static void DeleteDropboxImage(DropboxInfo dropBoxInfo) { // Make sure we remove it from the history, if no error occured config.runtimeDropboxHistory.Remove(dropBoxInfo.ID); config.DropboxUploadHistory.Remove(dropBoxInfo.ID); // get the config of dropbox Dropbox.DropBoxConfiguration dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as Dropbox.DropBoxConfiguration; // instanciate the cloudstorage manager CloudStorage storage = new CloudStorage(); // open the connection to the storage storage.Open(dropBoxConfig, config.DropboxAccessToken); // get the root entry of the cloud storage ICloudDirectoryEntry root = storage.GetRoot(); // delete a file ICloudFileSystemEntry fileSystemEntry = storage.GetFileSystemObject(dropBoxInfo.ID, root); if (fileSystemEntry != null) { storage.DeleteFileSystemEntry(fileSystemEntry); } // close the cloud storage connection if (storage.IsOpened) { storage.Close(); } dropBoxInfo.Image = null; }
public ActionResult GridViewPartialUpdate(inventarioImportaciones.Models.productos item) { var model = db.productos_List; if (ModelState.IsValid) { try { var modelItem = model.FirstOrDefault(it => it.Codigo == item.Codigo); if (item.Imagen.Length!=item.ImagenSelect.Length) { item.DirImagen = ""; string path = @"C:\Visual .net\DanielAsp"; string filename = path+"\\"+item.Nombre; var fsC = new BinaryWriter(new FileStream( filename + ".jpg", FileMode.Append, FileAccess.Write)); fsC.Write(item.ImagenSelect); fsC.Close(); CloudStorage dropBoxStorage = new CloudStorage(); var dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox); ICloudStorageAccessToken accessToken = null; // load a valid security token from file using (FileStream fs = System.IO.File.Open(@"C:\Visual .net\InventariosImportaciones\InventariosImportaciones\SharpDropBox.Token", FileMode.Open, FileAccess.Read, FileShare.None)) { accessToken = dropBoxStorage.DeserializeSecurityToken(fs); } var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken); var publicFolder = dropBoxStorage.GetFolder("/"); // GetFolder("/Public"); foreach (var fof in publicFolder) { // check if we have a directory Boolean bIsDirectory = fof is ICloudDirectoryEntry; // output the info Console.WriteLine("{0}: {1}", bIsDirectory ? "DIR" : "FIL", fof.Name); } String srcFile = Environment.ExpandEnvironmentVariables(filename + ".jpg"); ICloudFileSystemEntry fileUploaded= dropBoxStorage.UploadFile(srcFile, publicFolder); ICloudDirectoryEntry fEntry = dropBoxStorage.GetFolder("/"); ICloudFileSystemEntry fszz = dropBoxStorage.GetFileSystemObject("Gamma Quick Kids 21in.jpg", fEntry); string d = DropBoxStorageProviderTools.GetPublicObjectUrl(storageToken, fszz).AbsoluteUri; Console.WriteLine(d); dropBoxStorage.DownloadFile(publicFolder, item.Nombre + ".jpg", Environment.ExpandEnvironmentVariables(path)); dropBoxStorage.Close(); } if (modelItem != null) { this.UpdateModel(modelItem); db.SaveChanges(); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else ViewData["EditError"] = "Please, correct all errors."; return PartialView("_GridViewPartial", model.ToList()); }